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: play 1 hosts: localhost gather_facts: no tasks: - name: task1 in play1 shell: 'cat list_of_servers' register: task1_output - set_fact: server_list: "{{task1_output.stdout}}" - name: print the servers collected debug: msg: "{{server_list}}" - name: play 2 hosts: localhost gather_facts: no tasks: - name: printing the smb.conf from the target servers debug: msg: "{{lookup('file', '/etc/samba/smb.conf')}}" - name: printing the /etc/issue from the target servers debug: msg: "{{lookup('file', '/etc/issue')}}" Let's assume that after multiple tasks execution in play1, I got a list of servers. (list exactly ... in set_fact) server1 server11 server111 I want to use those variables as an input to the second play(play2). Logically .. the second play must be executed with (- e server1) and after all the tasks in play2 executed .. it should re-run play2 with (-e server 11) and the loop should continue until the server111. Is it possible to pass the variables which are the output from play1 as an input variable to play with multiple tasks ? On looping ., is there a way to repeat the play2(with all its tasks) for the each listed item of the variables .. server1.. server11.. server111) $ ap Untitled-2.yml PLAY [play 1] ************************************************************************************************************************* TASK [task1 in play1] ***************************************************************************************************************** changed: [localhost] TASK [set_fact] *********************************************************************************************************************** ok: [localhost] TASK [print the servers collected] **************************************************************************************************** ok: [localhost] => msg: |- server1.example.com server11.example.com server111.example.com PLAY [play 2] ************************************************************************************************************************* TASK [printing the smb.conf from the target servers] ********************************************************************************** fatal: [localhost]: FAILED! => msg: The 'file' lookup had an issue accessing the file '/etc/samba/smb.conf'. file not found, use -vvvvv to see paths searched PLAY RECAP **************************************************************************************************************************** localhost : ok=3 changed=1 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 On Thursday, September 21, 2023 at 8:25:02 PM UTC+5:30 Rowe, Walter P. (Fed) wrote: > Brian / Todd .. good eyes! > > > Walter > -- > Walter Rowe, Division Chief > Infrastructure Services, OISM > Mobile: 202.355.4123 <(202)%20355-4123> > > On Sep 21, 2023, at 10:22 AM, Brian Coca <bc...@redhat.com> 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 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 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-proje...@googlegroups.com. > > To view this discussion on the web visit > https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCACVha7f1zJc8ni3tG415F2EWiQDHZDyTVNnTZsvSvzgCzmgbSw%2540mail.gmail.com&data=05%7C01%7Cwalter.rowe%40nist.gov%7C8af8d8d876cf4490a1b808dbbaae4ad3%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638309029959489682%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=j7qzTtXfQ1g3uGSzohc4lw6cWSlGY3ySy6c67uEuia0%3D&reserved=0 > . > > > -- 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/804eb93b-9883-4d45-9c0c-137f714ecdcen%40googlegroups.com.