On Fri, 30 Aug 2019 02:41:12 -0700 (PDT)
Mohtashim S <
mohta...@gmail.com> wrote:
> The solution given with "my_list" is complaining of the below error:
> >
> > FAILED! => {"msg": "The task includes an option with an undefined
> > variable. The error was: 'dict object' has no attribute 'results'\n\nThe
> > error appears to be in
>
> Guess we need to relook at this proposed code snippet:
>
> my_list: "{{
> hostvars['localhost'].command_result.results|map(attribute='stdout')|list
> }}"
>
> Something is still wrong.
[SOLVED]
The playbook below
- hosts: localhost
tasks:
- set_fact:
Number: '42'
- set_fact:
InstallDir: '/usr/local'
- name: 'Collect Output'
command: "sh -c 'ls -1 /scratch/tmp/*.db'"
register: result
- hosts: test_01
tasks:
- set_fact:
My_list: "{{ hostvars['localhost'].result.stdout_lines|join(',') }}"
- set_fact:
Number: "{{ hostvars['localhost'].Number }}"
- set_fact:
InstallDir: "{{ hostvars['localhost'].InstallDir }}"
- shell: "/root/rollback.sh {{ Number }}
{{ InstallDir }}
{{ My_list }} > /root/rollback.log"
...
With the script
root@test_01:~ # cat /root/rollback.sh
#!/usr/local/bin/bash
echo $1
echo $2
echo $3
gives
root@test_01:~ # cat /root/rollback.log
42
/usr/local
/scratch/tmp/test1.db,/scratch/tmp/test2.db,/scratch/tmp/test3.db
--