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

   tasks:

     - debug: var=my_fact





 % ansible-playbook -i localhost, foo.yml


 PLAY [play 1] 
**********************************************************************************************************


 TASK [set_fact] 
********************************************************************************************************

 ok: [localhost]


 PLAY [play 2] 
**********************************************************************************************************


 TASK [debug] 
***********************************************************************************************************

 ok: [localhost] => {

     "my_fact": "this is a fact"

 }


 PLAY RECAP 
*************************************************************************************************************

 localhost                  : ok=2    changed=0    unreachable=0    failed=0    
skipped=0    rescued=0    ignored=0



Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Sep 21, 2023, at 8:02 AM, Veera <[email protected]> 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 
[email protected]<mailto:[email protected]>.
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CB89830F-FF55-4DB7-99F4-49EEBD210F6D%40nist.gov.

Reply via email to