Considering the following Ansible hosts
file:
[webservers]
server1.example.com ansible_ssh_pass=1234567
server2.example.com ansible_ssh_pass=2345678
server3.example.com ansible_ssh_pass=3456789
I would like to include these password values from a vault file and have a hosts
file like (my intention is to have an ini
inventory format):
[webservers]
server1.example.com ansible_ssh_pass={{ ssh_pass }}
server2.example.com ansible_ssh_pass={{ ssh_pass }}
server3.example.com ansible_ssh_pass={{ ssh_pass }}
where the sss_pass
variable comes from vaulted files defined in host_vars
folder.
The relevant ansible folder structure looks like this:
playbook.yml
inventories/
atlanta/
group_vars/
hosts
host_vars/
server1.example.com
server2.example.com
server3.example.com
But ansible is complaining:
[WARNING]: * Failed to parse /root/hsm-ansible-deploy/inventories/atlanta/hosts with ini plugin: /root/hsm-ansible-deploy/inventories/atlanta/hosts:18: Expected key=value host variable assignment, got: ssh_pass
- Why do I get the error?
- How can I import passwords into the
hosts
file?
ansible_ssh_pass: "{{ ssh_pass }}"
can actually be defined ingroup_vars
then thehosts
file is even cleaner. – Lucretialucretius