Working with hostvars across hosts of dynamic inventory

89 views
Skip to first unread message

Joseph Djomeda

unread,
Aug 27, 2015, 5:06:34 AM8/27/15
to ansible...@googlegroups.com
Hello All,

I have been struggling for quite a while now sharing some registered variables during ec2 instances provisioning hosts: localhost with their configuration hosts: tag_Name_tagname of ec2.

Kindly have a look at this sample http://pastie.org/10378851 . In hosts: tag_MName_myappdblivemaster , I need to set the hostname of all the instances created during - name: Launch myapp DB Instances Availability A and - name: Launch myapp DB Instances Availability B.

Because I have not found any way of using the variable myapp_db_ec2_a and myapp_db_ec2_b in the other hosts like tag_MName_myappdblivemaster in particular, I had to break the run, copy the hostnames from the console and paste in in playbook before this can be successful. When I try with hostvars['localhost'] , I get basically nothing to work with.

Is there any thing I am missing or it's not possible?

Best Regards,
--
Joseph Kodjo-Kuma Djomeda
check out my pains at : www.mycodingpains.com
We become what we think about ourselves........

benno joy

unread,
Aug 27, 2015, 6:07:25 AM8/27/15
to ansible...@googlegroups.com
Hi,

A registered variable persists only during the play, so maybe you could make them  facts which persists across plays  as below

- set_fact:

     registered_var: "{{ registered_var }}"


and then it shoudl be available via hostvars['localhost']


- Benno




--
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/CAKDXoaL5WDpGmH2zAB1hthb8suPXXMrCcx2pN2%2BbWhOF22Nz7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Joseph Djomeda

unread,
Aug 27, 2015, 9:16:09 AM8/27/15
to ansible...@googlegroups.com
Hello Benno,

I have tried your suggestion with set_fact but it didn't work. http://pastie.org/10379408 has both the playbook and it's output

Best Regards,


For more options, visit https://groups.google.com/d/optout.

benno joy

unread,
Aug 27, 2015, 10:13:50 AM8/27/15
to ansible...@googlegroups.com
Hi Joseph,

which version of ansible  are you on ?

- Benno


benno joy

unread,
Aug 27, 2015, 10:31:02 AM8/27/15
to ansible...@googlegroups.com
just checked the code, registered variable shoudl also persist across plays.. please do let us know the verison of ansible and i can check.

- Benno

Joseph Djomeda

unread,
Aug 27, 2015, 10:33:35 AM8/27/15
to ansible...@googlegroups.com
Hello Benno,

I am using ansible 1.9.2

Thanks


For more options, visit https://groups.google.com/d/optout.

benno joy

unread,
Aug 27, 2015, 10:42:06 AM8/27/15
to ansible...@googlegroups.com
can you please try hostvars['127.0.0.1']

Joseph Djomeda

unread,
Aug 27, 2015, 11:01:12 AM8/27/15
to ansible...@googlegroups.com
Hello Benno,
 Totally awesome, loopback worked. thanks a million

Best Regards,


For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages