Ansible block + with_together

11 views
Skip to first unread message

Shyam Sunder

unread,
Jul 22, 2019, 12:58:02 PM7/22/19
to Ansible Project
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.

Kai Stian Olstad

unread,
Jul 22, 2019, 1:50:11 PM7/22/19
to ansible...@googlegroups.com
On 22.07.2019 18:58, Shyam Sunder wrote:
> Hi There,
>
> I am new with Ansible and still figuring out how to use with_together with
> block.

It's not possible to use with_* on block only on task
https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html#block


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages