From 1a27b50fb24acf4594ff0c0104446e241977de2b Mon Sep 17 00:00:00 2001 From: Max Mehl Date: Thu, 29 Feb 2024 09:54:38 +0100 Subject: [PATCH] catch GPG error --- ansible-vault-tools.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ansible-vault-tools.py b/ansible-vault-tools.py index aa7b9cc..3af0b8e 100755 --- a/ansible-vault-tools.py +++ b/ansible-vault-tools.py @@ -11,7 +11,6 @@ import json import os import subprocess import sys -import getpass parser = argparse.ArgumentParser(description=__doc__) subparsers = parser.add_subparsers(title="commands", dest="command", required=True) @@ -160,9 +159,12 @@ def decrypt_string(host, var) -> str: "ANSIBLE_LOAD_CALLBACK_PLUGINS": "1", "ANSIBLE_STDOUT_CALLBACK": "json", } - result = subprocess.run( - ansible_command, env=ansible_env, capture_output=True, text=True, check=False - ) + try: + result = subprocess.run( + ansible_command, env=ansible_env, capture_output=True, text=True, check=True + ) + except subprocess.CalledProcessError as e: + sys.exit(f"Decrypting the variable failed: {e.stderr}") # Parse JSON try: