If I have the following entry in the Ansible file hosts:
[dbserver]
myserver
Then, elsewhere in my task code, I can refer to myserverhow {{ groups['dbserver'][0] }}to get the host name dynamically. It works great.
Now a similar scenario. Say I changed the file hoststo:
[dbserver]
db1 ansible_host=myserver ansible_user=myuser
What I found out is that {{ groups['dbserver'][0] }}it will now return "db1" and it seems to be a simple line. But what if I need to refer both to the actual hostname "myserver" and to know the user "myuser". How to access these values?
source
share