Search code examples
ansibleansible-2.xansible-inventoryansible-facts

How can I specify different ansible_password for each host in my playbook?


In inventory file(.ini) we can do this by using :

app-server-1 ansible_host="123.45.67.8" ansible_user=abcd ansible_password=mypwd

but since I want to encrypt the password using ansible vault, I need to put it in a .yml file.

A sample example would be highly appreciated as I have tried specifying in hosts: section and in vars: section, but could not do it when each host has different password.


Solution

  • Here's example of yaml inventory with generating encrypted password under the group. Here's example of yaml inventory with host variables:

    all:
      hosts:
        test1:
          ansible_password:  !vault |
                   $ANSIBLE_VAULT;1.2;AES256;my_user
                   66386134653765386232383236303063623663343437643766386435663632343266393064373933
                   3661666132363339303639353538316662616638356631650a316338316663666439383138353032
                   63393934343937373637306162366265383461316334383132626462656463363630613832313562
                   3837646266663835640a313164343535316666653031353763613037656362613535633538386539
                   65656439626166666363323435613131643066353762333232326232323565376635