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 can even chain them and make it future proof
set_fact:
uberHost: "{{
ansible_host|default(ansible_ssh_host|default(inventory_hostname,
True), True) }}"