you can even chain them and make it future proof
set_fact:
    uberHost: "{{
ansible_host|default(ansible_ssh_host|default(inventory_hostname,
True), True) }}"

On Tue, Jan 19, 2016 at 9:56 AM, Matt Martz <m...@sivel.net> wrote:
> It should be enough to just check:
>
> when: ansible_ssh_host
>
> However it may be good to come at it from a little different direction and
> use something like:
>
> set_fact:
>     uberHost: "{{ ansible_ssh_host|default(inventory_hostname, True) }}"
>
> The True in default() will tell jinja2 to use pythons truthyness checks, so
> an empty string evaluates as false as well.
>
>
> On Tuesday, January 19, 2016, Michael Baydoun <indymicha...@gmail.com>
> wrote:
>>
>> pre 2.0
>>
>> set_fact:
>>   uberHost: "{{ ansible_ssh_host }}"
>> when: ansible_ssh_host is defined
>>
>> set fact:
>>   uberHost: "{{ inventory_hostname }}"
>> when: ansible_ssh_host is not defined
>>
>>
>> Post 2.0, changed to use ansible_host
>> uberHost is always getting set to null
>> ansible_host is defined and set to null even when it's not present in the
>> inventory file
>> I haven't figured out how to test to see if ansible_host is null in a when
>> clause.
>>
>>
>> --
>> 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/ce3c97d5-f321-4ab6-868f-e83a11aa863f%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Matt Martz
> @sivel
> sivel.net
>
> --
> 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/CAD8N0v8bGu5GQSjKHJfKpXeir8vBnxoR0jhH6f6%2Bgkp3qAOOYw%40mail.gmail.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/CAJ5XC8kM0Vq7ePzv9QsgXxFbyB-W9UX3JmsEAXMybmBRXPqLSA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to