From f9036133bb69ed3f6ee9eaceea02374a4a92009d Mon Sep 17 00:00:00 2001 From: Jacob McGill Date: Fri, 25 Aug 2017 02:35:00 -0400 Subject: [PATCH] ACI Tenant: Update module to use new URL Method (#28640) --- lib/ansible/modules/network/aci/aci_tenant.py | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/network/aci/aci_tenant.py b/lib/ansible/modules/network/aci/aci_tenant.py index ae367b1363..0941af3ef2 100644 --- a/lib/ansible/modules/network/aci/aci_tenant.py +++ b/lib/ansible/modules/network/aci/aci_tenant.py @@ -98,6 +98,10 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, + required_if=[ + ['state', 'absent', ['tenant']], + ['state', 'present', ['tenant']], + ], ) tenant = module.params['tenant'] @@ -105,23 +109,18 @@ def main(): state = module.params['state'] aci = ACIModule(module) - - if tenant is not None: - # Work with a specific object - path = 'api/mo/uni/tn-%(tenant)s.json' % module.params - elif state == 'query': - # Query all objects - path = 'api/class/fvTenant.json' - else: - module.fail_json(msg="Parameter 'tenant' is required for state 'absent' or 'present'") - - aci.result['url'] = '%(protocol)s://%(hostname)s/' % aci.params + path - + aci.construct_url(root_class="tenant") aci.get_existing() if state == 'present': # Filter out module parameters with null values - aci.payload(aci_class='fvTenant', class_config=dict(name=tenant, descr=description)) + aci.payload( + aci_class='fvTenant', + class_config=dict( + name=tenant, + descr=description, + ), + ) # Generate config diff which will be used as POST request body aci.get_diff(aci_class='fvTenant')