Working with hostvars across hosts of dynamic inventory

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,

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

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,

Hi Joseph,

which version of ansible are you on ?

  • Benno

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

Hello Benno,

I am using ansible 1.9.2

Thanks

can you please try hostvars[‘127.0.0.1’]

Hello Benno,

Totally awesome, loopback worked. thanks a million

Best Regards,