# read multiple variables from dynamically generated file

**URL:** <https://forum.ansible.com/t/read-multiple-variables-from-dynamically-generated-file/15874>\
**Category:** Ansible Project\
**Created:** [August 6, 2014, 5:55pm UTC](https://forum.ansible.com/t/read-multiple-variables-from-dynamically-generated-file/15874 "2014-08-06T17:55:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Baydoun](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@Michael\_Baydoun](https://forum.ansible.com/u/Michael_Baydoun)\
**Post date:** [August 6, 2014, 5:55pm UTC](https://forum.ansible.com/t/read-multiple-variables-from-dynamically-generated-file/15874/1 "2014-08-06T17:55:38Z")

</div>

I have a playbook that runs on all database servers, gathers information about every database found, does error checking and eliminated duplicates (same db on mulitple servers). The result is an output file that contains three fields for every database “DBNAME SCRIPTNAME HOSTNAME”

Next I want to read every line in that local file, connect to only those hosts specified, and run the script providing the dbname as an argument. How can I read that dynamic local file and populated multiple variables for additional use?

Example file  
ProdDB script1.sh host1  
DevDB script47.sh host4

I want to do something like this

- name: retrieve tablespace data  
shell: /path/{{ scriptname }} {{ dbname }}  
delegate\_to: {{ hostname }}  
with items from file local.generated where field 1 is dbname, field 2 is scriptname, and field 3 is hostname  
register: tablespace\_data

whether or not I use delegate\_to, or call another playbook with extra vars, I still need to populate variables based on their position in a 1-n row text file. Any ideas how I can pull something like that off?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [August 7, 2014, 9:19pm UTC](https://forum.ansible.com/t/read-multiple-variables-from-dynamically-generated-file/15874/2 "2014-08-07T21:19:14Z")

</div>

"Next I want to read every line in that local file, connect to only those hosts specified, and run the script providing the dbname as an argument. "

Sounds like you should perhaps write a dynamic inventory script that understands this file, _OR_ change your playbook1 system to generate something in ansible inventory format.

However, you should be aware of concurrency issues of interlacing output. In general, avoiding dynamic generation of such files and using the “add\_host” module might be easier.
