I would like to reuse some variables defined under a role in an inventory file. For example,
a file inventory/myhost, it contains following line
myhost ansible_ssh_host={{ myhost_ip_address }}
By reading Ansible documentation and searching possible solutions, I did not get a solution so far. I’m wondering if it’s possible to use variable in inventory. Your help will be much appreciated. Thanks!
Regards,
Chenxiong Qi
the variable
ansible_ssh_hos
t will just be available for that host
you can also access it from another host as
hostvars.myhost.ansible_ssh_host or hostvars['myhost']['ansible_ssh_host']
In this case, you should be able to use it.
In general, you just have to be mindful of where a variable gets used
and templated and where it gets defined.
Since connection variables get used after role imports, this should
not be a problem.