# Use encyrpted pwd in ansible inventory file

**URL:** <https://forum.ansible.com/t/use-encyrpted-pwd-in-ansible-inventory-file/37251>\
**Category:** Ansible Project\
**Created:** [October 20, 2022, 8:23am UTC](https://forum.ansible.com/t/use-encyrpted-pwd-in-ansible-inventory-file/37251 "2022-10-20T08:23:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saravanan\_jothilinga](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@saravanan\_jothilinga](https://forum.ansible.com/u/saravanan_jothilinga)\
**Post date:** [October 20, 2022, 8:23am UTC](https://forum.ansible.com/t/use-encyrpted-pwd-in-ansible-inventory-file/37251/1 "2022-10-20T08:23:34Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 20, 2022, 3:58pm UTC](https://forum.ansible.com/t/use-encyrpted-pwd-in-ansible-inventory-file/37251/2 "2022-10-20T15:58:02Z")

</div>

Use 'inline vaults'  
[https://docs.ansible.com/ansible/latest/user\_guide/vault.html#encrypting-individual-variables-with-ansible-vault](https://docs.ansible.com/ansible/latest/user_guide/vault.html#encrypting-individual-variables-with-ansible-vault)

so you can have  
...  
all:  
&nbsp;&nbsp;hosts:  
&nbsp;&nbsp;&nbsp;&nbsp;hostname:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# per host  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ansible\_password: !vault |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ANSIBLE\_VAULT;1.2;AES256;dev  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30613233633461343837653833666333643061636561303338373661313838333565653635353162  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3263363434623733343538653462613064333634333464660a663633623939393439316636633863  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;61636237636537333938306331383339353265363239643939666639386530626330633337633833  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6664656334373166630a363736393262666465663432613932613036303963343263623137386239  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6330  
vars:  
&nbsp;&nbsp;&nbsp;# per group  
&nbsp;&nbsp;&nbsp;ansible\_password: ...

---

<div class="post-metadata">

**Author:** ![saravanan\_jothilinga](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@saravanan\_jothilinga](https://forum.ansible.com/u/saravanan_jothilinga)\
**Post date:** [October 23, 2022, 6:20am UTC](https://forum.ansible.com/t/use-encyrpted-pwd-in-ansible-inventory-file/37251/3 "2022-10-23T06:20:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 24, 2022, 5:26pm UTC](https://forum.ansible.com/t/use-encyrpted-pwd-in-ansible-inventory-file/37251/4 "2022-10-24T17:26:11Z")

</div>

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