Lets say I have a playbook like below
- name: install nagios client
hosts: client1
roles:
- nagios-client
set_fact:
client_ip: "{{ ansible_default_ipv4.address }}"
client_hostname: "{{ ansible_hostname }}"
- name: register client
hosts: server
vars:
- ip: {{ client_ip }}
- hostname: {{ client_hostname }}
role:
- register-nagios-client
I know that set_fact is bound to one host and cannot be used in another, also that you can get the IP of the client from facts {{ hostvars['client1']['ansible_eth0']['ipv4']['address'] }}
. But is there a work around to define a local variable that can be referenced in multiple places in the yml file?