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