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()