Re: [ansible-project] How to Pick and match the inventory_hostname against {{ ansible_hostname }} using groups.hosts

2018-03-12 Thread Brian Coca
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.

when: inventory_hostname == groups.hosts[0]

On Mon, Mar 12, 2018 at 12:01 PM,   wrote:
> @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
>
>
> On Monday, March 12, 2018 at 9:02:11 PM UTC+5:30, Brian Coca wrote:
>>
>> 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:
>>
>>
>> when: inventory_hostname == ansible_hostname
>>
>>
>> that will skip the task when they don't match.
>>
>>
>> if you want the task to actually fail:
>>
>>
>> failed_when: inventory_hostname != ansiblie_hostname
>>
>>
>> --
>> Brian Coca
>
> --
> 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-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ca01ad77-4c40-4f5e-8162-32636a1c7a6a%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 
--
Brian Coca

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7dSTJNBaoHaje7oELuvOq9a1g-XFE9KSB2%2B-F1gzDjKYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to Pick and match the inventory_hostname against {{ ansible_hostname }} using groups.hosts

2018-03-12 Thread rraka1002
@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

On Monday, March 12, 2018 at 9:02:11 PM UTC+5:30, Brian Coca wrote:
>
> 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: 
>
>
> when: inventory_hostname == ansible_hostname 
>
>
> that will skip the task when they don't match. 
>
>
> if you want the task to actually fail: 
>
>
> failed_when: inventory_hostname != ansiblie_hostname 
>
>
> -- 
> Brian Coca 
>

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ca01ad77-4c40-4f5e-8162-32636a1c7a6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to Pick and match the inventory_hostname against {{ ansible_hostname }} using groups.hosts

2018-03-12 Thread Brian Coca
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:


when: inventory_hostname == ansible_hostname


that will skip the task when they don't match.


if you want the task to actually fail:


failed_when: inventory_hostname != ansiblie_hostname


--
Brian Coca

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7cQFB8xe5OsmSEgWvT67imB_6MEFf5OcT3eLb--ckgDJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.