From fa795788cd7fa6f78c0aee73299ba8454d5606da Mon Sep 17 00:00:00 2001 From: Eero Aaltonen Date: Sun, 1 Mar 2026 23:34:17 +0200 Subject: [PATCH] fixup handle import errors as instructed in devguide https://docs.ansible.com/projects/ansible-core/devel/dev_guide/testing/sanity/import.html#in-plugins --- plugins/action/pgp_keyring.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/action/pgp_keyring.py b/plugins/action/pgp_keyring.py index 28891e8b3f..e003918039 100644 --- a/plugins/action/pgp_keyring.py +++ b/plugins/action/pgp_keyring.py @@ -18,8 +18,10 @@ from ansible.plugins.action import ActionBase try: import pgpy -except Exception as e: - raise AnsibleError('PGPym~=0.6.1 must be installed to use pgp_keyring plugin') from e +except ImportError as imp_exc: + PGPY_IMPORT_ERROR = imp_exc +else: + PGPY_IMPORT_ERROR = None class ActionModule(ActionBase): @@ -29,6 +31,9 @@ class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): """ Install PGP keyrings in binary format """ + if PGPY_IMPORT_ERROR: + raise AnsibleError('PGPym~=0.6.1 must be installed to use pgp_keyring plugin') from PGPY_IMPORT_ERROR + if task_vars is None: task_vars = dict()