diff --git a/plugins/modules/aoscx_vrf.py b/plugins/modules/aoscx_vrf.py index b66909c..3ce31ee 100644 --- a/plugins/modules/aoscx_vrf.py +++ b/plugins/modules/aoscx_vrf.py @@ -28,6 +28,10 @@ description: The name of the VRF required: true type: str + rd: + description: The Route Distinguisher (RD) of the VRF (use XXXXX:YYYYY for the format) + required: false + type: str state: description: Create or delete the VRF. required: false @@ -44,6 +48,12 @@ name: red state: create +- name: Create a VRF with RD + aoscx_vrf: + name: red + rd: 100:1 + state: create + - name: Delete a VRF aoscx_vrf: name: red @@ -64,6 +74,11 @@ def get_argument_spec(): "type": "str", "required": True, }, + "rd": { + "type": "str", + "required": False, + }, + "state": { "type": "str", "default": "create", @@ -85,6 +100,7 @@ def main(): # Get playbook's arguments vrf_name = ansible_module.params["name"] state = ansible_module.params["state"] + rd = ansible_module.params["rd"] result = dict(changed=False) @@ -114,6 +130,7 @@ def main(): modified = True if state == "create": + # Create VRF with incoming attributes if not vrf_exists: # Changed @@ -124,6 +141,11 @@ def main(): except Exception as e: ansible_module.fail_json(msg=str(e)) + # Configure RD (Route Distinguisher) + if rd: + vrf.rd = rd + modified |= vrf.apply() + result["changed"] = modified ansible_module.exit_json(**result) diff --git a/tests/integration/targets/aoscx_vrf/tests/api/rd.yaml b/tests/integration/targets/aoscx_vrf/tests/api/rd.yaml new file mode 100644 index 0000000..ea6aa9b --- /dev/null +++ b/tests/integration/targets/aoscx_vrf/tests/api/rd.yaml @@ -0,0 +1,76 @@ +--- +- debug: + msg: START aoscx_vrf rd (create/modify) integration tests on connection={{ ansible_connection }} + +- import_tasks: _remove_config.yaml + +- block: + +# - import_tasks: _populate.yaml + + - name: Create vrf with RD + register: result + aoscx_vrf: + name: ansible_vrf_test_1 + rd: "23:23" + state: create + + - name: Get vrf facts + register: vrf_facts + aoscx_facts: + gather_network_resources: + - vrfs + + - name: Assert if vrf is not created with rd + ansible.builtin.assert: + that: + - "'ansible_vrf_test_1' in vrf_facts.ansible_facts.ansible_network_resources.vrfs" + - vrf_facts.ansible_facts.ansible_network_resources.vrfs.ansible_vrf_test_1.rd == '23:23' + + - name: Create vrf with RD (idempotent) + register: result + aoscx_vrf: + name: ansible_vrf_test_1 + rd: "23:23" + state: create + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - not result['changed'] + +# Modify + - name: Modify vrf with RD + register: result + aoscx_vrf: + name: ansible_vrf_test_1 + rd: "44:44" + state: create + + - name: Get vrf facts + register: vrf_facts + aoscx_facts: + gather_network_resources: + - vrfs + + - name: Assert if vrf is not modifiy with rd + ansible.builtin.assert: + that: + - "'ansible_vrf_test_1' in vrf_facts.ansible_facts.ansible_network_resources.vrfs" + - vrf_facts.ansible_facts.ansible_network_resources.vrfs.ansible_vrf_test_1.rd == '44:44' + + - name: Modify vrf with RD (idempotent) + register: result + aoscx_vrf: + name: ansible_vrf_test_1 + rd: "44:44" + state: create + + - name: Assert that the previous task was idempotent + ansible.builtin.assert: + that: + - not result['changed'] + + always: + + - import_tasks: _remove_config.yaml