Skip to content

Commit

Permalink
Simplify logic
Browse files Browse the repository at this point in the history
Use device_info_get instead of calling cisco.dcnm.dcnm_inventory directly to retrieve serialNumber, isVpcConfigured, switchDbID
Use vpc_config_get to cull local vpc configuration
  • Loading branch information
allenrobel committed Aug 20, 2022
1 parent e380b8a commit 6f51f91
Showing 1 changed file with 32 additions and 43 deletions.
75 changes: 32 additions & 43 deletions roles/ndfc_vpc_interface_merged_all/tasks/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,48 @@
# - else
# skip

# set_fact for p1_serial, p1_vpc, p1_db_id
- name: worker query {{ item.fabric }} {{ item.vpc_name }} vpc_peer_1 {{ ip }}
cisco.dcnm.dcnm_inventory:
fabric: "{{ item.fabric }}"
state: query
config:
- seed_ip: "{{ ip }}"
register: wr1
- ansible.builtin.include_role:
name: ndfc_vpc_config_get
vars:
ansible_connection: httpapi
wq1: "[?fabric == '{{ item.fabric }}'] | [?vpc_name == '{{ item.vpc_name }}'].peer_1_ip | [0]"
ip: "{{ vpc_peers.values() | list | json_query(wq1)}}"
vpc_name: "{{ item.vpc_name }}"

- name: worker set_fact {{ item.fabric }} {{ item.vpc_name }} {{ item.vpc_port_id }} - p1_serial, p1_vpc, p1_db_id, p1_ip
set_fact:
p1_serial: "{{ wr1.response | json_query(wq2) }}"
p1_vpc: "{{ wr1.response | json_query(wq3) }}"
p1_db_id: "{{ wr1.response | json_query(wq4) }}"
p1_ip: "{{ wr1.response | json_query(wq5) }}"
- ansible.builtin.include_role:
name: ndfc_device_config_get
vars:
wq2: "[0].serialNumber"
wq3: "[0].isVpcConfigured"
wq4: "[0].switchDbID"
wq5: "[0].ipAddress"
device_name: "{{ vpc_config.peer_1 }}"

# set_fact for p2_serial, p2_vpc, p2_db_id
- name: worker query {{ item.fabric }} {{ item.vpc_name }} vpc_peer_2 {{ ip }}
cisco.dcnm.dcnm_inventory:
fabric: "{{ item.fabric }}"
state: query
config:
- seed_ip: "{{ ip }}"
register: wr2
- ansible.builtin.include_role:
name: ndfc_device_info_get
vars:
ansible_connection: httpapi
wq6: "[?fabric == '{{ item.fabric }}'] | [?vpc_name == '{{ item.vpc_name }}'].peer_2_ip | [0]"
ip: "{{ vpc_peers.values() | list | json_query(wq6)}}"
device_name: "{{ vpc_config.peer_1 }}"

- name: worker set_fact {{ item.fabric }} {{ item.vpc_name }} {{ item.vpc_port_id }} - p2_serial, p2_vpc, p2_db_id, p2_ip
- name: worker set_fact vpc_peer_1 {{ device_config.switch_fabric }} {{ item.vpc_name }} {{ item.vpc_port_id }} - p1_serial, p1_vpc, p1_db_id, p1_ip
set_fact:
p2_serial: "{{ wr2.response | json_query(wq7) }}"
p2_vpc: "{{ wr2.response | json_query(wq8) }}"
p2_db_id: "{{ wr2.response | json_query(wq9) }}"
p2_ip: "{{ wr2.response | json_query(wq10) }}"
p1_serial: "{{ device_info.serialNumber }}"
p1_vpc: "{{ device_info.isVpcConfigured }}"
p1_db_id: "{{ device_info.switchDbID }}"
p1_ip: "{{ device_info.ipAddress }}"

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

- ansible.builtin.include_role:
name: ndfc_device_info_get
vars:
wq7: "[0].serialNumber"
wq8: "[0].isVpcConfigured"
wq9: "[0].switchDbID"
wq10: "[0].ipAddress"
device_name: "{{ vpc_config.peer_2 }}"

- name: worker set_fact vpc_peer_2 {{ device_config.switch_fabric }} {{ item.vpc_name }} {{ item.vpc_port_id }} - p2_serial, p2_vpc, p2_db_id, p2_ip
set_fact:
p2_serial: "{{ device_info.serialNumber }}"
p2_vpc: "{{ device_info.isVpcConfigured }}"
p2_db_id: "{{ device_info.switchDbID }}"
p2_ip: "{{ device_info.ipAddress }}"

- name: worker merged fabric {{ item.fabric }} vpc_name {{ item.vpc_name }} vpc_port_id {{ item.vpc_port_id }} interface_mode {{ item.interface_mode }} ip {{ p1_ip }}/{{p2_ip}}
- name: worker merged fabric {{ device_config.switch_fabric }} vpc_name {{ item.vpc_name }} vpc_port_id {{ item.vpc_port_id }} interface_mode {{ item.interface_mode }} ip {{ p1_ip }}/{{p2_ip}}
cisco.dcnm.dcnm_interface:
fabric: "{{ item.fabric }}"
fabric: "{{ device_config.switch_fabric }}"
state: merged
config:
- name: "{{ item.vpc_port_id }}"
Expand Down

0 comments on commit 6f51f91

Please sign in to comment.