On Fri, 30 Aug 2019 02:41:12 -0700 (PDT)
Mohtashim S <[email protected]> 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

--

-- 
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/20190831102403.1456976b%40gmail.com.

Attachment: pgp5GzGLD85sE.pgp
Description: OpenPGP digital signature

Reply via email to