Recalling Part of the Cost of Ansible Inventory Record

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?

+4
source share
1

ansible_host ansible_user , hostvars:

- debug:
    var: hostvars['db1']['ansible_host']
- debug:
    var: hostvars['db1']['ansible_user']
+3

Source: https://habr.com/ru/post/1666053/


All Articles