Run 1 playbok on multiple hosts with different passwords

Hello,

I am trying to run ansible playbook on mutiple hosts with different passwords.

I tried this:

ansible-playbook -i hosts test2.yml --extra-vars “ansible_user=root ansible_password=dfth ansible_password=yuij”

But it connects only one host and gives authentication issue for another.

PLAY [Hello World!] ****************************************************************************************************************************************************

TASK [Hello World!] ****************************************************************************************************************************************************
changed: [172.20.24.xx]
fatal: [10.1.242.163]: UNREACHABLE! => {“changed”: false, “msg”: “Authentication failure.”, “unreachable”: true}
to retry, use: --limit @/root/test/test2.retry

PLAY RECAP *************************************************************************************************************************************************************
10.1.242.xx : ok=0 changed=0 unreachable=1 failed=0
172.20.24.xx : ok=1 changed=1 unreachable=0 failed=0

[root@vuhplabspawx001 test]#

Please help me to accomplish this, I am new to ansible. :slight_smile: Your prompt response is highly appreciated

Thanks in advance.

In your hosts file, you could define the SSH password for each host like:

[servers]
192.168.1.1 ansible_connection=ssh ansible_ssh_user=user1 ansible_ssh_pass=pass1
192.168.1.2 ansible_connection=ssh ansible_ssh_user=user1 ansible_ssh_pass=pass2

I’ve not tested this as I haven’t used password authentication in years, but it should work.

Hope this helps.

  • Gonzalo

Thanks , For your prompt response.