Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Refactor to simplify logic by removing direct call to cisco.dcnm.dcnm_inventory and replacing with device_info_get
  • Loading branch information
allenrobel committed Aug 23, 2022
1 parent 1a6b807 commit 753aa6a
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions roles/ndfc_rest_vpc_create/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,41 @@
- ansible.builtin.include_role:
name: ndfc_vpc_config_get

# peer_1

- ansible.builtin.include_role:
name: ndfc_device_config_get
vars:
device_name: "{{ vpc_config.peer_1 }}"

# TODO: Use ndfc_device_info_get to retrieve serialNumber, isVpcConfigured, switchDbID (see ndfc_vpc_interface_config_merged)
# set_fact for p1_serial, p1_vpc, p1_db_id
- name: main query FABRIC {{ device_config.switch_fabric }} VPC {{ vpc_name }} vpc_peer_1 {{ device_config.ip }}
cisco.dcnm.dcnm_inventory:
fabric: "{{ device_config.switch_fabric }}"
state: query
config:
- seed_ip: "{{ device_config.ip }}"
register: mr1
- ansible.builtin.include_role:
name: ndfc_device_info_get
vars:
ansible_connection: httpapi
device_name: "{{ vpc_config.peer_1 }}"

- name: main set_fact p1_serial, p1_vpc, p1_db_id
- name: worker set_fact vpc_peer_1 {{ device_config.switch_fabric }} {{ vpc_name }} - p1_serial, p1_vpc, p1_db_id
set_fact:
p1_serial: "{{ mr1.response | json_query(mq2) }}"
p1_vpc: "{{ mr1.response | json_query(mq3) }}"
p1_db_id: "{{ mr1.response | json_query(mq4) }}"
vars:
mq2: "[0].serialNumber"
mq3: "[0].isVpcConfigured"
mq4: "[0].switchDbID"
p1_serial: "{{ device_info.serialNumber }}"
p1_vpc: "{{ device_info.isVpcConfigured }}"
p1_db_id: "{{ device_info.switchDbID }}"

# peer_2

- ansible.builtin.include_role:
name: ndfc_device_config_get
vars:
device_name: "{{ vpc_config.peer_2 }}"

# TODO: Use ndfc_device_info_get to retrieve serialNumber, isVpcConfigured, switchDbID (see ndfc_vpc_interface_config_merged)
# set_fact for p2_serial, p2_vpc, p2_db_id
- name: main query FABRIC {{ device_config.switch_fabric }} VPC {{ vpc_name }} vpc_peer_2
cisco.dcnm.dcnm_inventory:
fabric: "{{ device_config.switch_fabric }}"
state: query
config:
- seed_ip: "{{ device_config.ip }}"
register: mr2
- ansible.builtin.include_role:
name: ndfc_device_info_get
vars:
ansible_connection: httpapi
device_name: "{{ vpc_config.peer_2 }}"

- name: main set_fact p2_serial, p2_vpc, p2_db_id
- name: worker set_fact vpc_peer_1 {{ device_config.switch_fabric }} {{ vpc_name }} - p2_serial, p2_vpc, p2_db_id
set_fact:
p2_serial: "{{ mr2.response | json_query(mq6) }}"
p2_vpc: "{{ mr2.response | json_query(mq7) }}"
p2_db_id: "{{ mr2.response | json_query(mq8) }}"
vars:
mq6: "[0].serialNumber"
mq7: "[0].isVpcConfigured"
mq8: "[0].switchDbID"
p2_serial: "{{ device_info.serialNumber }}"
p2_vpc: "{{ device_info.isVpcConfigured }}"
p2_db_id: "{{ device_info.switchDbID }}"

# Conditionally create vpc peering
- name: main REST create VPC Peers fabric_name {{ device_config.switch_fabric }} vpc_name {{ vpc_name }} configured {{ p1_vpc }}/{{ p2_vpc }} serial_number {{ p1_serial }}/{{ p2_serial }}"
Expand Down

0 comments on commit 753aa6a

Please sign in to comment.