read multiple variables from dynamically generated file

37 views
Skip to first unread message

Michael Baydoun

unread,
Aug 6, 2014, 1:55:38 PM8/6/14
to ansible...@googlegroups.com
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?

Michael DeHaan

unread,
Aug 7, 2014, 5:19:18 PM8/7/14
to ansible...@googlegroups.com
"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.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4d72f74d-b895-4805-9594-b41406c559a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages