I have a script that I run at the start of my first play like this.

*- hosts: localhost*
*  local_action: command python runScript.py *

It gnerates me a file in *roles/abc/vars/main.yml* which looks like this.

*newHosts:*
*   - hostIP: 192.168.1.23*
*     filename: file1*
*   - hostIP: 192.168.1.24*
*     filename: file2*

Then I call the role by

* roles:*
*   - { role: abc }*

in that role, I'm trying to add those hosts to inventory_host as well as in 
the group by doing this:

*add_host: hostname= {{ item.hostIP }} groups=newHosts filename= {{ 
item.filename }}*
*with_items: newHosts*


The problem is that the first time when I run this play; the script runs 
and generates the file and when the role is called it gives me the error

*fatal: [127.0.0.1] => One or more undefined variables: 'unicode object' 
has no attribute 'hostIP'*

*FATAL: all hosts have already failed -- aborting*

which is logical because the file *roles/abc/var/main.yml* didn't exist in 
the beginning. The second time when I run the playbook. it runs without any 
problem.

So, can you guide me how can I add the hosts from a file which is generated 
at the run-time and use it in the same play?

Thanking you in anticipation.

Warm Regards,
Fazal-e-Rehman Khan

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b8f9725f-9b81-4ed5-b269-9af18cbf3770%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to