Answer the question
In order to leave comments, you need to log in
How to access host variables in Ansible?
I have a group with a host
[app_admin]
adm-01.local
Answer the question
In order to leave comments, you need to log in
Everything turned out to be simple:
in the inventory file we set:
[app_admin]
adm_01 ansible_host=adm-01.local
[app_admin]
adm_01
Everything is much easier. If the variable is specified in host_vars or group_vars, then just refer to it from anywhere.
For group_vars. File group_vars/app_admin
:
Ie all hosts in the app_admin group have myvar defined with the value my_value_for_app_admin_group. If you need to redefine a variable for some hosts, then you should use host_vars. File host_vars/adm-01.local
:
To refer to a variable in a role, playbook or warm it is necessary like this {{ myvar }}
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question