Can you suggest what is the issue with this code ?

   - name: Add hosts
     include_tasks: "{{ playbook_dir }}/gethosts.yml"
       dest_ip: "{{ item.split('\t')[0] }}"
       groups: dest_nodes
       file_dets: "{{ item.split('\t')[1] }}"
       ansible_host: localhost
       ansible_connection: local
     with_items: "{{ command_result.stdout_lines }}"


And below is my get_hosts.yml file

     add_host:
       name: "{{ item }}"   
     with_items: "{{ dest_ip.split(',') }}"

On Tuesday, September 24, 2019 at 2:01:17 PM UTC+5:30, Vladimir Botka wrote:
>
> On Mon, 23 Sep 2019 23:44:58 -0700 (PDT) 
> Mohtashim S <[email protected] <javascript:>> wrote: 
>
> > command_result variable has has data like below. 
> > 
> > host6,host5\targ3 
> > host4,host3\targ1 
> > host1,host2,host5\targ2 
> > ..... 
> > ..... 
> > 
> > I need to loop through each line of command_result. Pick the host list 
> for 
> > example host6,host5 and execute shell script using shell module by 
> passing 
> > respective argument string i.e arg3. 
>
> Given the input is a list 'db_lines' normalise the data first. For example 
> the loop below 
>
>   vars: 
>     separator: '\t' 
>     db_lines: 
>       - 'host6,host5\targ3' 
>       - 'host4,host3\targ1' 
>       - 'host1,host2,host5\targ2' 
>   tasks: 
>     - set_fact: 
>         my_data: "{{ my_data|default([]) + 
>                      [{'host': item.split(separator)[0].split(','), 
>                        'arg': item.split(separator)[1].split(',')}] }}" 
>       loop: "{{ db_lines }}" 
>
> gives 
>
>   my_data: 
>   - arg: 
>     - arg3 
>     host: 
>     - host6 
>     - host5 
>   - arg: 
>     - arg1 
>     host: 
>     - host4 
>     - host3 
>   - arg: 
>     - arg2 
>     host: 
>     - host1 
>     - host2 
>     - host5 
>
> It should be trivial to use it in the loops. 
>
> 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/b560e24a-c84a-46e2-9672-383f4ba648f0%40googlegroups.com.

Reply via email to