I have 10 Linux servers. I am going to change the password of the root user for all servers. I have written a playbook with “expect” and “user” modules, but I need to run this playbook separately for each server.
[php]
*My playbook for change eatch server password
I am looking for a solution to set a different password for each server through a playbook. for example :
[php]
var1: server1
var2: server2
var3: server3
.
.
.
var10: server10
I know that passwords and servers should be defined as variables, but I don’t know how to write the playbook. I would be grateful if you could advise me on this matter.
Run the playbook: ansible-playbook -i ~/workspace/inventory ~/workspace/play_change_passwords.yml
Key Takeaways and Things to Research
Inventory and Passwords
Do not use this inventory file in production. The playbook idea is alright, but handling inventories and passwords should not be done like I have above.
Ansible Setup
Research how to setup a basic ansible-core environment. This Ansible Documentation is a great starting point.
Ansible Vaults
Research how to use ansible-vault command and ANSIBLE_VAULT_PASSWORD_FILE environment variable to begin securely storing passwords and other sensitive information. For example, this is where you would store root_password: YourRootPassword
Host Vars
Research how to setup a host_vars directory and use it to store variables that are unique to each host in your inventory.