# How to Segregate Inventory file and Group Variable to provide Ansible User name and password

**URL:** <https://forum.ansible.com/t/how-to-segregate-inventory-file-and-group-variable-to-provide-ansible-user-name-and-password/33202>\
**Category:** Ansible Project\
**Created:** [June 17, 2020, 3:07pm UTC](https://forum.ansible.com/t/how-to-segregate-inventory-file-and-group-variable-to-provide-ansible-user-name-and-password/33202 "2020-06-17T15:07:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ditun\_dhar](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@ditun\_dhar](https://forum.ansible.com/u/ditun_dhar)\
**Post date:** [June 17, 2020, 3:07pm UTC](https://forum.ansible.com/t/how-to-segregate-inventory-file-and-group-variable-to-provide-ansible-user-name-and-password/33202/1 "2020-06-17T15:07:27Z")

</div>

Guys,

I am new in Ansible and need some help. I am in need of segregating my inventory file (which will change continuously based on another script output) with credential file. However Ansible username, password and admin password will be same or static. I want to create a group variable file to store credential and that should be encrypted using vault.

Can you give some direction to hook my group variable file to inventory file in Ansible playbook

Regards,

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [June 17, 2020, 3:31pm UTC](https://forum.ansible.com/t/how-to-segregate-inventory-file-and-group-variable-to-provide-ansible-user-name-and-password/33202/2 "2020-06-17T15:31:48Z")

</div>

> Guys,
> 
> I am new in Ansible and need some help. I am in need of segregating my inventory file (which will change continuously  
> based on another script output) with credential file. However Ansible username, password and admin password will be same  
> or static. I want to create a group variable file to store credential and that should be encrypted using vault.
> 
> Can you give some direction to hook my group variable file to inventory file in Ansible playbook

You can have separate files for your "main" inventory and group variables.

Let's say your inventory is "production", you can set it up like that:

production/production.yml =\> "main" inventory  
production/group\_vars/mygroup.yml =\> contains group variables

You can encrypt your group variable file with:

ansible-vault encrypt production/group\_vars/mygroup.yml

Given that your "main" inventory changes dynamically, check out these resources:

[https://docs.ansible.com/ansible/latest/user\_guide/intro\_dynamic\_inventory.html](https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html)  
[https://docs.ansible.com/ansible/latest/dev\_guide/developing\_inventory.html](https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html)

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![ditun\_dhar](https://avatars.discourse-cdn.com/v4/letter/d/838e76/32.png) [@ditun\_dhar](https://forum.ansible.com/u/ditun_dhar)\
**Post date:** [June 18, 2020, 6:56pm UTC](https://forum.ansible.com/t/how-to-segregate-inventory-file-and-group-variable-to-provide-ansible-user-name-and-password/33202/3 "2020-06-18T18:56:27Z")

</div>

Thanks Racke,  
It is solved now.😊

Regards,  
Souvik
