Ansible: Is the any chance of maintain same tag same role but diffrent host name in main yml file by putting any when condition from tasks inside role.

20 views
Skip to first unread message

dvenur...@gmail.com

unread,
Sep 18, 2020, 3:54:38 AM9/18/20
to Ansible Project

I have tried to maintain my main yml file like below
       ----
        hosts: "{{ windows_hostname1 }}"
        gather_facts: no
        roles:
          - Windows
     
        hosts: "{{ windows_hostname2 }}"
        gather_facts: no
        roles:
          - Windows

and my tasks are inside the windows role with same tag name is there any chance of putting when condition to this hosts variable in tasks so I can diffrentiate the execution for two windows hosts.

I have two windows devices which deals differenct tasks.

Thanks in advance.

Gajendra Gaikwad

unread,
Sep 19, 2020, 2:42:25 PM9/19/20
to ansible...@googlegroups.com
Hi,

when: inventory_hostname in groups['small_group']
Or 
when: inventory_hostname == {{ windows_hostname1 }}


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3dbdf35b-0b0e-40f4-82d1-b98787a12e6fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages