Re: [ansible-project] Ansible - use variable from another host

2018-02-22 Thread Brian Coca
hostvars requires a string that is a host name: hostvars['']
, if the 'windows' is a hostname you can do
hostvars['windows']['varname'] .. if it is a group , you cannot do
this, you need to use a specific hostname.

But if you just want any host in the group you can do :
hostvars[groups['windows'][0]]['value_to_reuse']['stdout_lines']

Also note that if you don't quote something it will be interpreted as
a variable that contains the name, not the variable name you want
(list indecies are an exception as they are just numbers).




-- 
--
Brian Coca

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7eyuGVd98GjbwmaRHC7G-rKC9QyhR2jGZcYSx7EorHuYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Ansible - use variable from another host

2018-02-22 Thread Larry Bakun
I have a playbook that executes a script on a Windows box that returns a 
value that I have to re-use later on in my playbook after switching to the 
localhost. How can I access this value after switching back to localhost. 
Here is an example:


hosts: localhost
connection: local
gather_facts: no
tasks:
.
.
.
hosts: windows
gather_facts: no
tasks:
- name: Call PowerShell script
win_command: "c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe 
c:\\psl_scripts\\getData.ps1"
register: value_to_reuse

hosts: localhost
gather_facts: no
connection: local
tasks:
- name: debug store_name from windows host
 debug:
 var: "{{ hostvars[windows][value_to_reuse][stdout_lines] }}"




What is the correct syntax accessing a variable from another host? I'm 
receiving error message: *"msg": "The task includes an option with an 
undefined variable. The error was: 'windows' is undefined*

-- 
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-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/97fe8978-e84b-404b-85bb-c1dd41635cb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.