# Reading data from a file?

**URL:** <https://forum.ansible.com/t/reading-data-from-a-file/15999>\
**Category:** Ansible Project\
**Created:** [August 21, 2014, 11:22am UTC](https://forum.ansible.com/t/reading-data-from-a-file/15999 "2014-08-21T11:22:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimbobpalmer](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@jimbobpalmer](https://forum.ansible.com/u/jimbobpalmer)\
**Post date:** [August 21, 2014, 11:22am UTC](https://forum.ansible.com/t/reading-data-from-a-file/15999/1 "2014-08-21T11:22:12Z")

</div>

Hi.

I’m quite new to ansible.

I have an iptables module that takes an array of ip addresses and generates iptables rules using a template. It works well. It’s called like this:

- { role: iptables, whitelisted\_ips: [  
‘1.1.1.1’, # dave  
‘2.2.2.2’, # dave  
‘3.3.3.3’, # dave  
‘4.4.4.4’, # malcolm  
‘5.5.5.5’, # edna  
] }

As you can see, Dave has a lot of ip addresses. I’d like to call it like this instead:

- { role: iptables, whitelisted\_ips: [‘dave’, ‘malcolm’, ‘edna’,] }

But I don’t know where to start. How can I do this?

Hope someone can help.

---

<div class="post-metadata">

**Author:** ![Henry\_Finucane](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@Henry\_Finucane](https://forum.ansible.com/u/Henry_Finucane)\
**Post date:** [August 22, 2014, 2:58am UTC](https://forum.ansible.com/t/reading-data-from-a-file/15999/2 "2014-08-22T02:58:32Z")

</div>

If you want to reference a previous variable, it's going to have to be  
a scalar, and you have to do something like this:

whitelisted\_ips: [ "{{dave}}", "{{malcolm}}" ...

The way I've been doing things like this is setting up a dict for the  
environment or group like this:

&nbsp;&nbsp;&nbsp;&nbsp;whitelisted\_ips:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dave:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 1.1.1.1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 2.2.2.2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;malcolm:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 4.4.4.4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;edna:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- 5.5.5.5

And then calling roles like this:

- role: iptables

I like it because if you want to know what the settings are for a  
group, you look at the group vars, or the environment, the environment  
vars, instead of having it in the playbook, which is sort of the wrong  
layer. I also have separate dicts for administrative concerns-  
everything in the environment is going to be the same, there- and  
services, where each group is liable to be different.
