Hello Jordan,

That's exactly my problem! Now i understand why it's not on the second
play. I get the variable again on the second play and it's working properly.

Thanks a lot for the exaplanation!
David

On Tue, May 8, 2018, 22:00 Jordan Borean <[email protected]> wrote:

> Without seeing the full playbook it is hard to actually confirm what you
> are doing but it sounds like you have 2 plays in your playbook, 1 to get
> the host info and add it, the other to run tasks on that new host. When you
> run set_fact or register in a play, that variable/fact is only registered
> for the hosts it is running on. If you were to run a 2nd play on a
> different set of hosts those variables are no longer accessible like you
> would do it normally. What you need to do is access those variables from
> the hostvars dict and specify the original host, I'm going to guess the
> first play is run on localhost so it would be *{{
> hostvars['localhost']['endpoint'] }}*. Here is an example of it in action
>
>
> - name: 1st play that runs on localhost and defines the var
>   hosts: localhost
>   tasks:
>   - name: set variable/fact on the first play for localhost
>     set_fact:
>       my_var: abc
>
> - name: 2nd play that runs on another host
>   hosts: other-group
>   tasks:
>   - name: output my_var registered on localhost
>     debug:
>       var: hostvars['localhost']['my_var']
>
> As you can see, the 2nd play runs on a different group and I use hostvars
> to lookup the variables defined on localhost and finally get the my_var
> variable.
>
> Thanks
>
> Jordan
>
> --
> 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/423db0a1-4405-4f50-bab4-3afe35ec23a9%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/423db0a1-4405-4f50-bab4-3afe35ec23a9%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAFGRPVp6STH1Bt1ZG%3DPx-_5ex4YdGJeO7HSbuPXP57bq3uT8Kg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to