I created a variable in group_vars
group_vars/all
---
hostname: name1
I want to set name2 to the real host(10.20.30.40), so I created a file and set the hostname again there
host_vars/10.20.30.40
---
hostname: name2
When I run the playbook, it returned name1 but not name2:
roles/os/tasks/main.yml
- name: Print hostname
ansible.builtin.debug:
msg: "{{ hostname }}"
Result:
TASK [server : Print hostname] *************************************
ok: [web_server] => {
"msg": "name1"
}
I want to set the variable in each host that I want to update, isn't it the right usage?
And, if I name the host file this way under the host_vars folder, does it work?
web_server
The inventory:
[web_server]
10.20.30.40
playbook:
---
- hosts: web_server
become: true
vars_files:
- group_vars/all
roles:
- os