~xenrox/ansible

ref: 9919fb2efcb3e891d2618ea418058fbf40a659f1 ansible/misc/run.py -rwxr-xr-x 863 bytes
9919fb2eThorben Günther CI: Run playbooks with ansible-runner 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python

import sys
from os import environ

import ansible_runner
from requests import post

if len(sys.argv) != 2:
    sys.exit("One playbook needs to be specified.")

playbook_name = sys.argv[1]
playbook = "playbooks/" + playbook_name + ".yml"
r = ansible_runner.run(private_data_dir=".", playbook=playbook)

changes = list(r.stats["changed"].values())[0]
message = "[Playbook]({}) deployed with **{}** changes."
build_url = environ["JOB_URL"]
gotify_token = environ["GOTIFY_TOKEN"]

if changes > 0:
    post(
        "https://gotify.xenrox.net/message?token=" + gotify_token,
        json={
            "message": message.format(build_url, changes),
            "priority": 7,
            "Title": playbook_name + " status",
            "extras": {
                "client::display": {"contentType": "text/markdown"},
            },
        },
    )