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 *ansible_hostname*, *inventory_hostname*, and *ansible_fqdn*.

On 9/21/23 8:02 AM, Veera wrote:
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
    - name: collect the hostname for the next task
set_fact:
reg_name: "{{short_name.stdout_lines[-1].split('.')[1] }}"
- name: Playbook to test the new hostname collections
hosts: 127.0.0.1
become: yes
tasks:
    - name: print  the collected hostname
debug:
msg: {{reg_name  }}

 collecting  the host's shortname using set_fact is  working .  However the data stored using set_fact in reg_name is  not carry to the next task. Is there an option/module available to have the variable from one task to be made available to the next?


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e414a185-f743-4618-ab14-b4449dfecf6dn%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/e414a185-f743-4618-ab14-b4449dfecf6dn%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
Todd

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/07db4399-5d76-c624-afb7-03483c29e52c%40gmail.com.

Reply via email to