diff --git a/plugins/module_utils/constants.py b/plugins/module_utils/constants.py index d6d9d521e..35b209978 100644 --- a/plugins/module_utils/constants.py +++ b/plugins/module_utils/constants.py @@ -439,3 +439,5 @@ ] MATCH_ACCESS_POLICIES_SELECTOR_TYPE = dict(range="range", all="ALL") + +MANAGEMENT_EPG_TYPE = dict(ooband="oob", inband="inb") diff --git a/plugins/modules/aci_dns_profile.py b/plugins/modules/aci_dns_profile.py index a4a535a73..5a8f4aab1 100644 --- a/plugins/modules/aci_dns_profile.py +++ b/plugins/modules/aci_dns_profile.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # Copyright: (c) 2022, Tim Cragg (@timcragg) +# Copyright: (c) 2024, Akini Ross (@akinross) # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function @@ -22,6 +23,19 @@ - Name of the DNS profile. type: str aliases: [ name, profile_name ] + management_epg: + description: + - Name of the management EPG. + - Specify C("") to remove the management EPG configuration. + type: str + aliases: [ epg ] + management_epg_type: + description: + - The type of the management EPG. + type: str + choices: [ inband, ooband ] + aliases: [ type ] + default: ooband state: description: - Use C(present) or C(absent) for adding or removing. @@ -39,6 +53,7 @@ link: https://developer.cisco.com/docs/apic-mim-ref/ author: - Tim Cragg (@timcragg) +- Akini Ross (@akinross) """ EXAMPLES = r""" @@ -51,13 +66,35 @@ state: present delegate_to: localhost -- name: Remove a DNS profile +- name: Add a new DNS profile with a inband management EPG cisco.aci.aci_dns_profile: host: apic username: admin password: SomeSecretPassword dns_profile: my_dns_prof - state: absent + management_epg: ansible_mgmt_epg_inband + management_epg_type: inband + state: present + delegate_to: localhost + +- name: Add a new DNS profile with a out-of-band management EPG + cisco.aci.aci_dns_profile: + host: apic + username: admin + password: SomeSecretPassword + dns_profile: my_dns_prof + management_epg: ansible_mgmt_epg_ooband + state: present + delegate_to: localhost + +- name: Remove a management EPG from a DNS profile + cisco.aci.aci_dns_profile: + host: apic + username: admin + password: SomeSecretPassword + dns_profile: my_dns_prof + management_epg: "" + state: present delegate_to: localhost - name: Query a DNS profile @@ -78,6 +115,15 @@ state: query delegate_to: localhost register: query_result + +- name: Remove a DNS profile + cisco.aci.aci_dns_profile: + host: apic + username: admin + password: SomeSecretPassword + dns_profile: my_dns_prof + state: absent + delegate_to: localhost """ RETURN = r""" @@ -187,6 +233,7 @@ from ansible.module_utils.basic import AnsibleModule from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec +from ansible_collections.cisco.aci.plugins.module_utils.constants import MANAGEMENT_EPG_TYPE def main(): @@ -194,6 +241,8 @@ def main(): argument_spec.update(aci_annotation_spec()) argument_spec.update( dns_profile=dict(type="str", aliases=["name", "profile_name"]), + management_epg=dict(type="str", aliases=["epg"]), + management_epg_type=dict(type="str", default="ooband", choices=["inband", "ooband"], aliases=["type"]), state=dict(type="str", default="present", choices=["absent", "present", "query"]), ) @@ -207,8 +256,10 @@ def main(): ) dns_profile = module.params.get("dns_profile") + management_epg = module.params.get("management_epg") + management_epg_type = MANAGEMENT_EPG_TYPE.get(module.params.get("management_epg_type")) state = module.params.get("state") - child_classes = ["dnsProv", "dnsDomain"] + child_classes = ["dnsProv", "dnsDomain", "dnsRsProfileToEpg"] aci = ACIModule(module) aci.construct_url( @@ -224,9 +275,35 @@ def main(): aci.get_existing() if state == "present": + + child_configs = [] + if management_epg is not None: + if management_epg == "": + child_configs.append( + dict( + dnsRsProfileToEpg=dict( + attributes=dict( + tDn="", + status="deleted", + ) + ) + ) + ) + else: + child_configs.append( + dict( + dnsRsProfileToEpg=dict( + attributes=dict( + tDn="uni/tn-mgmt/mgmtp-default/{0}-{1}".format(management_epg_type, management_epg), + ) + ) + ) + ) + aci.payload( aci_class="dnsProfile", class_config=dict(name=dns_profile), + child_configs=child_configs, ) aci.get_diff(aci_class="dnsProfile") diff --git a/tests/integration/targets/aci_dns_profile/tasks/main.yml b/tests/integration/targets/aci_dns_profile/tasks/main.yml index 027532f63..94264e7a1 100644 --- a/tests/integration/targets/aci_dns_profile/tasks/main.yml +++ b/tests/integration/targets/aci_dns_profile/tasks/main.yml @@ -1,5 +1,6 @@ # Test code for the ACI modules # Copyright: (c) 2021, Tim Cragg (@timcragg) +# Copyright: (c) 2024, Akini Ross (@akinross) # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) @@ -20,6 +21,16 @@ use_proxy: '{{ aci_use_proxy | default(true) }}' output_level: debug +# CLEAN DNS PROFILES +- name: Remove DNS profiles before testing + cisco.aci.aci_dns_profile: + <<: *aci_info + profile_name: "{{ item }}" + state: absent + loop: + - ansible_dns_profile + - ansible_dns_profile_mamagement_epg + # ADD DNS PROFILE - name: Add DNS profile cisco.aci.aci_dns_profile: @@ -51,6 +62,70 @@ - add_dns_profile_again.current.0.dnsProfile.attributes.dn == "uni/fabric/dnsp-ansible_dns_profile" - add_dns_profile_again.current.0.dnsProfile.attributes.name == "ansible_dns_profile" +# ADD MGMT EPG TO DNS PROFILE + +- name: Add ooband management EPG to DNS profile (check-mode) + cisco.aci.aci_dns_profile: &aci_dns_profile_ooband + <<: *aci_info + profile_name: ansible_dns_profile_mamagement_epg + management_epg: ansible_mgmt_epg_ooband + state: present + check_mode: yes + register: cm_add_ooband_mgmt_epg_to_dns_profile + +- name: Add ooband management EPG to DNS profile + cisco.aci.aci_dns_profile: + <<: *aci_dns_profile_ooband + state: present + register: nm_add_ooband_mgmt_epg_to_dns_profile + +- name: Add ooband management EPG to DNS profile again to test idempotence + cisco.aci.aci_dns_profile: + <<: *aci_dns_profile_ooband + state: present + register: nm_add_ooband_mgmt_epg_to_dns_profile_again + +- name: Update ooband management EPG to inband management EPG + cisco.aci.aci_dns_profile: + <<: *aci_dns_profile_ooband + management_epg: ansible_mgmt_epg_inband + management_epg_type: inband + state: present + register: nm_update_ooband_mgmt_epg_to_inband_mgmt_epg + +- name: Remove management EPG from DNS profile + cisco.aci.aci_dns_profile: + <<: *aci_dns_profile_ooband + management_epg: "" + state: present + register: nm_remove_inband_mgmt_epg_from_dns_profile + +- name: Verify DNS profile with management EPGs + ansible.builtin.assert: + that: + - cm_add_ooband_mgmt_epg_to_dns_profile is changed + - cm_add_ooband_mgmt_epg_to_dns_profile.previous == [] + - cm_add_ooband_mgmt_epg_to_dns_profile.proposed.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg" + - cm_add_ooband_mgmt_epg_to_dns_profile.proposed.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband" + - nm_add_ooband_mgmt_epg_to_dns_profile is changed + - nm_add_ooband_mgmt_epg_to_dns_profile.previous == [] + - nm_add_ooband_mgmt_epg_to_dns_profile.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg" + - nm_add_ooband_mgmt_epg_to_dns_profile.current.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband" + - nm_add_ooband_mgmt_epg_to_dns_profile_again is not changed + - nm_add_ooband_mgmt_epg_to_dns_profile_again.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg" + - nm_add_ooband_mgmt_epg_to_dns_profile_again.previous.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband" + - nm_add_ooband_mgmt_epg_to_dns_profile_again.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg" + - nm_add_ooband_mgmt_epg_to_dns_profile_again.current.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband" + - nm_update_ooband_mgmt_epg_to_inband_mgmt_epg is changed + - nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg" + - nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.previous.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband" + - nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg" + - nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.current.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/inb-ansible_mgmt_epg_inband" + - nm_remove_inband_mgmt_epg_from_dns_profile is changed + - nm_remove_inband_mgmt_epg_from_dns_profile.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg" + - nm_remove_inband_mgmt_epg_from_dns_profile.previous.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/inb-ansible_mgmt_epg_inband" + - nm_remove_inband_mgmt_epg_from_dns_profile.current.0.dnsProfile.children.0.dnsRsProfileToEpg is not defined + # QUERY DNS PROFILE - name: Query the DNS profile cisco.aci.aci_dns_profile: