# How to import host/group specific files into roles

**URL:** <https://forum.ansible.com/t/how-to-import-host-group-specific-files-into-roles/41375>\
**Category:** Get Help\
**Tags:** role\
**Created:** [March 27, 2025, 2:20pm UTC](https://forum.ansible.com/t/how-to-import-host-group-specific-files-into-roles/41375 "2025-03-27T14:20:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [March 27, 2025, 2:20pm UTC](https://forum.ansible.com/t/how-to-import-host-group-specific-files-into-roles/41375/1 "2025-03-27T14:20:07Z")

</div>

Hello Team,

I am using role to install the kafka. I need help in using environment specific files from roles directory to the ansible code and eventually deployed onto the servers.

For example we have some files which are changing as per enviornment.  
dev we have separate keystores and truststore  
prod we have separate keystores and truststore  
Now how can we use same role and variabalize to pick the env specific or group sepecific keystore/truststore or any other files??  
I would like to have those files in ansible roles permanently. It should pick from any directory under roles , ideally inventory or files.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [March 27, 2025, 3:45pm UTC](https://forum.ansible.com/t/how-to-import-host-group-specific-files-into-roles/41375/2 "2025-03-27T15:45:00Z")

</div>

you can use the `vars_from: '{{myenv}}.yml'` of `incluide_role`/`import_role` to specify the source, assuming the `myenv` variable is dev/prod/qa/staging.

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [April 1, 2025, 8:10am UTC](https://forum.ansible.com/t/how-to-import-host-group-specific-files-into-roles/41375/3 "2025-04-01T08:10:05Z")

</div>

Hello Brian, Thanks a lot. That can work but we are looking for more elegant solution something we can store all those keystores as per inventory group name or host names with proper directory structure. Like i wish to place all dev group specific files inside inventory/dev/dev\*.jks inventory/prod/prod.jks and then i want to use them in role playbook. Can this be done??

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [April 1, 2025, 1:31pm UTC](https://forum.ansible.com/t/how-to-import-host-group-specific-files-into-roles/41375/4 "2025-04-01T13:31:59Z")

</div>

create a group per inventory that matches the `{{inventory_file}}`, then put the per env info in `group_vars/<inventory_file>.yml`
