# Encrypting Host File

**URL:** <https://forum.ansible.com/t/encrypting-host-file/25218>\
**Category:** Ansible Project\
**Created:** [August 10, 2017, 8:51am UTC](https://forum.ansible.com/t/encrypting-host-file/25218 "2017-08-10T08:51:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siva](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Siva](https://forum.ansible.com/u/Siva)\
**Post date:** [August 10, 2017, 8:51am UTC](https://forum.ansible.com/t/encrypting-host-file/25218/1 "2017-08-10T08:51:03Z")

</div>

Hi,

Good Day!

I have a requirement to encrypt the host file in ansible, say for example, I want to encrypt the production environment host file so that the host information is not available with every one.

Can anyone tell me if this is achievable with Ansible Vault? Or any alternate way how I can get to this.

Regards,  
Siva

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 10, 2017, 10:35am UTC](https://forum.ansible.com/t/encrypting-host-file/25218/2 "2017-08-10T10:35:38Z")

</div>

Hi

---

<div class="post-metadata">

**Author:** ![Siva](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Siva](https://forum.ansible.com/u/Siva)\
**Post date:** [August 10, 2017, 10:45am UTC](https://forum.ansible.com/t/encrypting-host-file/25218/3 "2017-08-10T10:45:18Z")

</div>

Just to give more information of what I am trying.

> host (file name)
> 
> [server-a]  
> server-a
> 
> [server-b]  
> server-b

> [appserver:children]  
> server-a  
> server-b

> * * *

> host\_details (file name)

> [server-a:vars]
> 
> env\_name=server-a
> 
> ansible\_ssh\_user=root
> 
> ansible\_ssh\_host=10.0.0.1
> 
> ansible\_ssh\_private\_key\_file=~/.ssh/xyz-key.pem
> 
> [server-b:vars]
> 
> env\_name=server-b
> 
> ansible\_ssh\_user=root
> 
> ansible\_ssh\_host=10.0.0.2
> 
> ansible\_ssh\_private\_key\_file=~/.ssh/xyz-key.pem

- I am encrypting host\_details file using ansible vault.
- When I execute the playbook,
- Without encryption: Execution is successful
- With encryption: I get the below error,  
TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Thursday 10 August 2017 11:21:01 +0100 (0:00:00.053) 0:00:00.053 \*\*\*\*\*\*\*  
fatal: [server-a]: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: Could not resolve hostname server-a: Name or service not known\r\n”, “unreachable”: true}  
fatal: [server-b]: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: Could not resolve hostname server-b: Name or service not known\r\n”, “unreachable”: true}  
Add Comment

---

<div class="post-metadata">

**Author:** ![Siva](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Siva](https://forum.ansible.com/u/Siva)\
**Post date:** [August 10, 2017, 11:01am UTC](https://forum.ansible.com/t/encrypting-host-file/25218/4 "2017-08-10T11:01:28Z")

</div>

Host I mean is the inventory file.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 10, 2017, 12:14pm UTC](https://forum.ansible.com/t/encrypting-host-file/25218/5 "2017-08-10T12:14:56Z")

</div>

I see.

Just to be sure: how do you exactly call the playbook?

It shouldn't matter, but can you try given the inventory files a .yml extension?

Dick

---

<div class="post-metadata">

**Author:** ![Siva](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Siva](https://forum.ansible.com/u/Siva)\
**Post date:** [August 10, 2017, 3:05pm UTC](https://forum.ansible.com/t/encrypting-host-file/25218/6 "2017-08-10T15:05:58Z")

</div>

Hi Dick,

Thanks, your suggestion worked.
