Use encyrpted pwd in ansible inventory file

Hi.
I am novice to this ansible and trying out a few basic use cases to apply patches on remote linux servers. We are using a host based authentication approach to connect to remote servers and execute ansible playbooks there.

If we want to encrypt the password and use that encrypted password inside the inventory file, please suggest an efficient method to do that.

Cmd that i use- sudo ansible-playbook ping_host_test.yml -e “host=remoteserver” -k

cat ping_host_test.yml

  • hosts: ‘{{ host }}’
    gather_facts: true
    become: true

tasks:

  • name: Pinging Host {{ host }}
    action: ping
  • name: “Print os info”
    debug:
    msg: |
    The os is {{ ansible_distribution }}
    The env is {{ inventory_hostname }}

Thanks!

Use 'inline vaults'
https://docs.ansible.com/ansible/latest/user_guide/vault.html#encrypting-individual-variables-with-ansible-vault

so you can have
...
all:
  hosts:
    hostname:
           # per host
          ansible_password: !vault |
              $ANSIBLE_VAULT;1.2;AES256;dev
              30613233633461343837653833666333643061636561303338373661313838333565653635353162
              3263363434623733343538653462613064333634333464660a663633623939393439316636633863
              61636237636537333938306331383339353265363239643939666639386530626330633337633833
              6664656334373166630a363736393262666465663432613932613036303963343263623137386239
              6330
vars:
   # per group
   ansible_password: ...

Hi,
Thanks for your information.
Could you please share some examples where a user is able to encrypt the password using ansible vault and use that encrypted password in the ansible playbook’s host variable section. Appreciate your help on this.

Thanks
Saravanan

see my previous email? it has example of use, as for example of
creating the vault, I linked to the documentation