diff --git a/lib/ansible/modules/network/aci/aci_aep.py b/lib/ansible/modules/network/aci/aci_aep.py index dd724a7a11..a0c2aca044 100644 --- a/lib/ansible/modules/network/aci/aci_aep.py +++ b/lib/ansible/modules/network/aci/aci_aep.py @@ -97,6 +97,10 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, + required_if=[ + ['state', 'absent', ['aep']], + ['state', 'present', ['aep']], + ], ) aep = module.params['aep'] @@ -104,21 +108,18 @@ def main(): state = module.params['state'] aci = ACIModule(module) - - if aep is not None: - path = 'api/mo/uni/infra/attentp-%(aep)s.json' % module.params - elif state == 'query': - path = 'api/class/infraAttEntityP.json' - else: - module.fail_json(msg="Parameter 'aep' is required for state 'absent' or 'present'") - - aci.result['url'] = '%(protocol)s://%(hostname)s/' % aci.params + path - + aci.construct_url(root_class="aep") aci.get_existing() if state == 'present': # Filter out module parameters with null values - aci.payload(aci_class='infraAttEntityP', class_config=dict(name=aep, descr=description)) + aci.payload( + aci_class='infraAttEntityP', + class_config=dict( + name=aep, + descr=description, + ), + ) # Generate config diff which will be used as POST request body aci.get_diff(aci_class='infraAttEntityP')