# Need direction oh how to either Loop Variables or use Lists for Variables within Roles

**URL:** <https://forum.ansible.com/t/need-direction-oh-how-to-either-loop-variables-or-use-lists-for-variables-within-roles/31043>\
**Category:** Ansible Project\
**Created:** [August 14, 2019, 8:25pm UTC](https://forum.ansible.com/t/need-direction-oh-how-to-either-loop-variables-or-use-lists-for-variables-within-roles/31043 "2019-08-14T20:25:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CaptainBrewing](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@CaptainBrewing](https://forum.ansible.com/u/CaptainBrewing)\
**Post date:** [August 14, 2019, 8:25pm UTC](https://forum.ansible.com/t/need-direction-oh-how-to-either-loop-variables-or-use-lists-for-variables-within-roles/31043/1 "2019-08-14T20:25:25Z")

</div>

I have a role that configures a JSON file on a server. The JSON file needs know the following variables which are DIFFERENT for each server. This file is the later used to for a script that installs software

[root@ip-172-29-100-198 roles]# cat elasticconfig/\*\*defaults/\*\*main.yml

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 14, 2019, 9:11pm UTC](https://forum.ansible.com/t/need-direction-oh-how-to-either-loop-variables-or-use-lists-for-variables-within-roles/31043/2 "2019-08-14T21:11:58Z")

</div>

You should read this since it have you answers.  
[https://docs.ansible.com/ansible/latest/user\_guide/intro\_inventory.html](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html)

Either but the variable on every host in the inventory or create host\_vars an add one file for each host. But everything is explained in the link.

---

<div class="post-metadata">

**Author:** ![CaptainBrewing](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@CaptainBrewing](https://forum.ansible.com/u/CaptainBrewing)\
**Post date:** [August 14, 2019, 9:51pm UTC](https://forum.ansible.com/t/need-direction-oh-how-to-either-loop-variables-or-use-lists-for-variables-within-roles/31043/3 "2019-08-14T21:51:33Z")

</div>

Thanks Kai I did not realize that the inventory was actually used to set random Variables for hosts, if these variables did not have anything to do with the ssh configuration. Thanks
