~xenrox/ansible

ef2d0dbaa4d4aa4dc0e704dc9efe8d161a79c788 — Thorben Günther 1 year, 11 months ago 9919fb2
run.py: Exit gracefully when nothing changed
1 files changed, 9 insertions(+), 3 deletions(-)

M misc/run.py
M misc/run.py => misc/run.py +9 -3
@@ 13,16 13,22 @@ 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"]
changes_list = list(r.stats["changed"].values())
changes = 0

if len(changes_list) > 0:
    changes = changes_list[0]
if changes == 0:
    sys.exit()
message = "[Playbook]({}) deployed with **{}** changes.".format(build_url, changes)

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