I have created hosts:
sudo cat /etc/ansible/hosts
[Prospectorium]
192.168.1.50
[Scholarium]
192.168.1.60
[Bulwark]
192.168.1.70
And a playbook that should update those servers:
sudo cat /home/overlord/ansible/apt.yml
- hosts: all become: yes tasks:
- name: Update and upgrade apt packages.
apt:
update_cache: yes
upgrade: full
autoremove: yes
autoclean: yes
cache_valid_time: 43200
Each of those 3 hosts has a different username and password:
prospectorium
prospectorium123
scholarium
scholarium123
bulwark
bulwark123
So now my question: How can I securely pass login information when I run a playbook?
I tried creating a vault file, but that can contain only one password and no username, so that is not applicable to me.
There are more options. You might want to try the host_vars and group_vars first.
It seems the symbolic names are the names of the hosts rather than the names of the groups. See Inventory basics: formats, hosts, and groups. In this case, the inventory file might be
Put the passwords into the host_vars
Test it
Encrypt the passwords if this is what you want to. See details in Encrypting content with Ansible Vault
You can see that the files were encrypted and the ansible-inventory command shows the same result.
Test the structure in a playbook. For example, the playbook below
gives
You can add other variables into the encrypted files in host_vars if you want to.
An elegant option is putting the data into the group_vars/all.yml. For example
Encrypt group_vars/all.yml
Remove the host_vars and users from hosts
The same playbook gives the same result
You can put the variables into any file you want to and include them in a playbook. For example, remove all the host_vars and group_vars from the previous examples and put the file into the directory vars
Encrypt the file
Include the file in a playbook. For example, the playbook below gives the same result