From 2765ee4b9a035a1190faf7c7f3e7ff6d56d01973 Mon Sep 17 00:00:00 2001 From: Yaacov Zamir Date: Mon, 23 Oct 2017 14:33:57 +0300 Subject: [PATCH] Enable use of empty manageiq arguments (#31774) * anable use of empty manageiq arguments * make default verify_ssl true --- lib/ansible/module_utils/manageiq.py | 8 +++++- .../manageiq/manageiq_provider.py | 4 +-- .../manageiq/manageiq_tags.py | 21 ++++++++------- .../manageiq/manageiq_user.py | 26 ++++++++++--------- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/lib/ansible/module_utils/manageiq.py b/lib/ansible/module_utils/manageiq.py index 329d26d446..4f0c5e69ec 100755 --- a/lib/ansible/module_utils/manageiq.py +++ b/lib/ansible/module_utils/manageiq.py @@ -37,7 +37,7 @@ except ImportError: def manageiq_argument_spec(): - return dict( + options = dict( url=dict(default=os.environ.get('MIQ_URL', None)), username=dict(default=os.environ.get('MIQ_USERNAME', None)), password=dict(default=os.environ.get('MIQ_PASSWORD', None), no_log=True), @@ -46,6 +46,12 @@ def manageiq_argument_spec(): ca_bundle_path=dict(required=False, default=None), ) + return dict( + manageiq_connection=dict(type='dict', + default=dict(verify_ssl=True), + options=options), + ) + def check_client(module): if not HAS_CLIENT: diff --git a/lib/ansible/modules/remote_management/manageiq/manageiq_provider.py b/lib/ansible/modules/remote_management/manageiq/manageiq_provider.py index 6758f3a199..7d3dc77d8b 100644 --- a/lib/ansible/modules/remote_management/manageiq/manageiq_provider.py +++ b/lib/ansible/modules/remote_management/manageiq/manageiq_provider.py @@ -548,14 +548,14 @@ def main(): zone_id = None endpoints = [] argument_spec = dict( - manageiq_connection=dict(required=True, type='dict', - options=manageiq_argument_spec()), state=dict(choices=['absent', 'present'], default='present'), name=dict(required=True), zone=dict(default='default'), provider_region=dict(), type=dict(choices=supported_providers().keys()), ) + # add the manageiq connection arguments to the arguments + argument_spec.update(manageiq_argument_spec()) # add the endpoint arguments to the arguments argument_spec.update(endpoint_list_spec()) diff --git a/lib/ansible/modules/remote_management/manageiq/manageiq_tags.py b/lib/ansible/modules/remote_management/manageiq/manageiq_tags.py index e0da3c0d86..184b8b0a48 100644 --- a/lib/ansible/modules/remote_management/manageiq/manageiq_tags.py +++ b/lib/ansible/modules/remote_management/manageiq/manageiq_tags.py @@ -246,18 +246,19 @@ class ManageIQTags(object): def main(): actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'} + argument_spec = dict( + tags=dict(type='list'), + resource_name=dict(required=True, type='str'), + resource_type=dict(required=True, type='str', + choices=manageiq_entities().keys()), + state=dict(required=False, type='str', + choices=['present', 'absent', 'list'], default='present'), + ) + # add the manageiq connection arguments to the arguments + argument_spec.update(manageiq_argument_spec()) module = AnsibleModule( - argument_spec=dict( - manageiq_connection=dict(required=True, type='dict', - options=manageiq_argument_spec()), - tags=dict(type='list'), - resource_name=dict(required=True, type='str'), - resource_type=dict(required=True, type='str', - choices=manageiq_entities().keys()), - state=dict(required=False, type='str', - choices=['present', 'absent', 'list'], default='present'), - ), + argument_spec=argument_spec, required_if=[ ('state', 'present', ['tags']), ('state', 'absent', ['tags']) diff --git a/lib/ansible/modules/remote_management/manageiq/manageiq_user.py b/lib/ansible/modules/remote_management/manageiq/manageiq_user.py index 083dde2533..29d1c497ee 100755 --- a/lib/ansible/modules/remote_management/manageiq/manageiq_user.py +++ b/lib/ansible/modules/remote_management/manageiq/manageiq_user.py @@ -283,19 +283,21 @@ class ManageIQUser(object): def main(): + argument_spec = dict( + userid=dict(required=True, type='str'), + name=dict(), + password=dict(no_log=True), + group=dict(), + email=dict(), + state=dict(choices=['absent', 'present'], default='present'), + update_password=dict(choices=['always', 'on_create'], + default='always'), + ) + # add the manageiq connection arguments to the arguments + argument_spec.update(manageiq_argument_spec()) + module = AnsibleModule( - argument_spec=dict( - manageiq_connection=dict(required=True, type='dict', - options=manageiq_argument_spec()), - userid=dict(required=True, type='str'), - name=dict(), - password=dict(no_log=True), - group=dict(), - email=dict(), - state=dict(choices=['absent', 'present'], default='present'), - update_password=dict(choices=['always', 'on_create'], - default='always'), - ), + argument_spec=argument_spec, ) userid = module.params['userid']