Now i'm checking where "{{ ansible_hostname }}" should match the each "{{ inventory_hostname }}" and if "{{ inventory_hostname }}" matches with "{{ ansible_hostname }}" then proceed otherwise fail.
I tried using "when: inventory_hostname == groups.hosts" it didn't pich the hostnames Serially hence its getting failed, So, how to ensure the each "{{ inventory_hostname }}" can be red serially so it can run to all the hosts in a sequence so it may match the hostname correctlt and compare the condition.
Brian Coca
unread,
Mar 12, 2018, 11:32:11 AM3/12/18
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
First of all you are comparing a string (inventory_hostname) to a list
(groups.hosts, which is [host-test1, host-test2, noi-pranjala]).
if you want to match inventory-hostname to ansible_hostname, just do that:
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
@Brian , Thanks a lot for your suggestion, this looks Great,
What about "when: inventory_hostname == groups.hosts" when: inventory_hostname == groups.hosts[0] , i google around but did not get clear & explicit explanation about its usage
Brian Coca
unread,
Mar 12, 2018, 12:11:34 PM3/12/18
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
This is invalid, as i explained above:
when: inventory_hostname == groups.hosts"
This works when the 'current host' is also the 'first host in the
group', here [0] is an index on the list that is group.hosts, so it is
a valid comparison.