start getting modules to use shared import error code (#51787)

This commit is contained in:
Jordan Borean 2019-02-07 03:39:17 +10:00 committed by Sam Doran
commit 0f0d33a954
46 changed files with 230 additions and 108 deletions

View file

@ -72,13 +72,16 @@ old_value:
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils._text import to_native
try:
import etcd3
etcd_found = True
HAS_ETCD = True
except ImportError:
etcd_found = False
ETCD_IMP_ERR = traceback.format_exc()
HAS_ETCD = False
def run_module():
@ -112,8 +115,8 @@ def run_module():
result['key'] = module.params.get('key')
if not etcd_found:
module.fail_json(msg="the python etcd3 module is required")
if not HAS_ETCD:
module.fail_json(msg=missing_required_lib('etcd3'), exception=ETCD_IMP_ERR)
allowed_keys = ['host', 'port', 'ca_cert', 'cert_key', 'cert_cert',
'timeout', 'user', 'password']