I tried the suggested set_fact suggestion but looks like I need more help.
Getting the below error in Play-2
FAILED! => {"msg": "The task includes an option with an undefined variable.
The error was: 'command_result' is undefined\n\nThe error appears to be in
Here is the updated playbook
- name: Play 1
hosts: localhost
tasks:
- name: "Collect Output"
command: ls -ltr *
register: command_result
- set_fact:
command_result: "{{ command_result }}"
- name: Play 2
hosts: remotehost
tasks:
- shell: "~/rollback.sh {{ Number }} '{{ InstallDir }}'
'{{ command_result.stdout }}' > ~/rollback.log"
On Friday, August 30, 2019 at 2:03:25 PM UTC+5:30, Vladimir Botka wrote:
>
> On Fri, 30 Aug 2019 01:22:08 -0700 (PDT)
> Mohtashim S <[email protected] <javascript:>> wrote:
>
> > How to pass "stdout" of a variable "command_result" belonging to Ansible
> > Play-1 to shell module of a different Play-2?
> >
> > My playbook looks like below:
> >
> > - name: Play 1
> > hosts: localhost
> > tasks:
> > - name: "Collect Output"
> > command: ls -ltr *
> > register: command_result
>
> - set_fact:
> command_result: "{{ command_result }}"
>
> > - name: Play 2
> > hosts: remotehost
> > tasks:
> > - shell: "~/rollback.sh {{ Number }} '{{ InstallDir }}' '{{
> >
> hostvars[\"localhost\"][\"command_result\"].results|map(attribute=/'stdout/')|list
>
>
> > }}' > ~/rollback.log"
>
> Make the scope of "command_result" playbook-wide with "set_fact".
> Registered
> variables belong to the host which is running the play. i.e. "localhost"
> in
> your case. The second play runs "remotehost" who know nothing about
> varaibles
> registered by "localhost".
>
> Cheers,
>
> -vlado
>
--
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/29623e3e-269a-4149-a437-6d314bc75b29%40googlegroups.com.