diff --git a/lib/ansible/modules/network/aci/aci_tenant_action_rule_profile.py b/lib/ansible/modules/network/aci/aci_tenant_action_rule_profile.py index b0f6d139bd..e85bd2ae5b 100644 --- a/lib/ansible/modules/network/aci/aci_tenant_action_rule_profile.py +++ b/lib/ansible/modules/network/aci/aci_tenant_action_rule_profile.py @@ -82,31 +82,30 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, + required_if=[ + ['state', 'absent', ['action_rule', 'tenant']], + ['state', 'present', ['action_rule', 'tenant']], + ], ) action_rule = module.params['action_rule'] - # tenant = module.params['tenant'] description = module.params['description'] state = module.params['state'] aci = ACIModule(module) - - # TODO: This logic could be cleaner. - if action_rule is not None: - path = 'api/mo/uni/tn-%(tenant)s/attr-%(action_rule)s.json' % module.params - elif state == 'query': - # Query all objects - path = 'api/node/class/rtctrlAttrP.json' - else: - module.fail_json(msg="Parameter 'action_rule' is required for state 'absent' or 'present'") - - aci.result['url'] = '%(protocol)s://%(hostname)s/' % aci.params + path - + aci.construct_url(root_class='tenant', subclass_1='action_rule') aci.get_existing() if state == 'present': # Filter out module parameters with null values - aci.payload(aci_class='rtctrlAttrP', class_config=dict(name=action_rule, descr=description)) + aci.payload( + aci_class='rtctrlAttrP', + class_config=dict( + name=action_rule, + descr=description, + ), + + ) # Generate config diff which will be used as POST request body aci.get_diff(aci_class='rtctrlAttrP')