From bd1d25763443b6538ccf670f4ff5204a488396d8 Mon Sep 17 00:00:00 2001 From: Max Mehl Date: Wed, 6 Dec 2023 12:23:24 +0100 Subject: [PATCH] handle unfound host --- ansible-vault-tools.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ansible-vault-tools.py b/ansible-vault-tools.py index b1571c2..5acf2ea 100755 --- a/ansible-vault-tools.py +++ b/ansible-vault-tools.py @@ -86,7 +86,11 @@ def decrypt_string(host, var): result = subprocess.run(ansible_command, env=ansible_env, capture_output=True, text=True) # Parse JSON - ansible_output = json.loads(result.stdout)["plays"][0]["tasks"][0]["hosts"] + try: + ansible_output = json.loads(result.stdout)["plays"][0]["tasks"][0]["hosts"] + except IndexError: + print(f"ERROR: Host '{host}' not found.") + return "" # Attempt to create a :-separated list of host/values output = {}