From ef2d0dbaa4d4aa4dc0e704dc9efe8d161a79c788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Mon, 30 May 2022 15:07:19 +0200 Subject: [PATCH] run.py: Exit gracefully when nothing changed --- misc/run.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/misc/run.py b/misc/run.py index 3f311a1..df0f1fe 100755 --- a/misc/run.py +++ b/misc/run.py @@ -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": { -- 2.44.0