Hi There,
I am new with Ansible and still figuring out how to use with_together with block.
UseCase: Trying to compare configuration of device A and device B. Below is a snippet from my script.
`
-
hosts: pairB
connection: network_cli
name: script to audit HSRP config of pair B device
tasks:
-
name: running hsrp brief on device B
nxos_command:
commands:
- command: sh hsrp brief
output: json
register: hsrpB
-
hosts: localhost
vars:
deviceA: "{{ hostvars[groups['pairA'][0]]['hsrpA']['stdout'][0].TABLE_grp_detail.ROW_grp_detail }}"
deviceB: "{{ hostvars[groups['pairB'][0]]['hsrpB']['stdout'][0].TABLE_grp_detail.ROW_grp_detail }}"
tasks:
- name: compare hsrp config of device A and device B
block:
- name: "compare config"
debug:
msg: "check config of device A and device B"
when:
- item.0.sh_active_router_addr != item.1.sh_active_router_addr or item.0.sh_authentication_data != item.1.sh_authentication_data
- ((item.0.sh_prio < item.1.sh_prio and item.0.sh_group_state == "Active" and item.1.sh_group_state == "Standby") or (item.0.sh_prio > item.1.sh_prio and item.0.sh_group_state == "Standby" and item.1.sh_group_state == "Active"))
rescue:
- debug:
msg: "config does not match for device A and B"
with_together:
- "{{ deviceA }}"
- "{{ deviceB }}"
`
Can someone point me to a working example? or this is not possible with Ansible.