in play2 just use `hostvars['localhost']['server_list']`
--
--
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
Hi ,
I am re-opening this thread as I get a new question on above the existing
one.
Sorry for that..(not lazy to open another)
Is there a way to use the output of play1 , which is a list(of variables)
to be passed variable to the second play2
The playbook for illustration only .
---
- name
Brian / Todd .. good eyes!
Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
On Sep 21, 2023, at 10:22 AM, Brian Coca wrote:
You are confusing scopes, `set_fact` is PER HOST, not a global. So you
defined the variable on server1 but are trying to read it fr
yes. Exactly ..
I did set_fact on a remote_host and try to re-call the value of the
variable in the localhost.
*So to access in the 2nd play you need to go through
hostvars:{{hostvasr['server1']['reg_name']*
Do you mean I have to use like below?
- name: print the collected hostname
de
You are confusing scopes, `set_fact` is PER HOST, not a global. So you
defined the variable on server1 but are trying to read it from
127.0.0.1.
So to access in the 2nd play you need to go through hostvars:
{{hostvasr['server1']['reg_name']
--
--
Brian Coca
--
You received this message
Your first play is targeting *server1*, while your second play is
targeting a different host.
If the reg_name is available in the second task, you would need to
retrieve it relative to *server1*:
*msg: "{{ hostvars['server1']['reg_name'] }}"*
You should look at and contrast the values of
If you gather facts you can reference inventory_hostname_short vs running a
shell command.
https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#term-inventory_hostname_short
Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
O
Works for me ..
% ansible --version
ansible [core 2.15.4]
% cat foo.yml
---
- name: play 1
hosts: all
become: no
gather_facts: no
tasks:
- set_fact:
my_fact: "this is a fact"
- name: play 2
hosts: all
become: no
gather_facts: no
tas
I have a 2 tasks in a playbook and from task1 I have a variable collected
from the register output as below.
- name: Playbook to collect the actual hostname
hosts: server1
become: yes
tasks:
- name: collect the actual hostname
shell: 'hostname'
register: short_name