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

On Sep 21, 2023, at 8:02 AM, Veera <sveem...@gmail.com> 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<mailto: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>.

-- 
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/FF9075A2-E4A7-4E55-9413-872AF345EAC1%40nist.gov.

Reply via email to