On Mon, 9 Sep 2019 12:52:37 +0200
Vladimir Botka <vbo...@gmail.com> wrote:

> On Mon, 9 Sep 2019 00:54:32 -0700 (PDT)
> Danny Rehelis <auto...@gmail.com> wrote:
> 
> > > >  vars: 
> > > >    my_hosts: 
> > > >      - ['host1', 'host2'] 
> > > >      - ['host3'] 
> > > > [...] 
> > > > loop: "{{ my_hosts }}" 
> > > > [...] 
> > > > ERROR! Unexpected Exception, this is probably a bug: unhashable type:   
> > > >   
> 
> > >
> > > Flatten the lists. 
> > >
> > >       loop: "{{ my_hosts|flatten }}" 
> > >  
> 
> > What i'm trying to achieve is -
> >     "msg": {
> >         "all": [
> >             "host1",
> >             "host2",
> >             "host3"
> >         ],
> >         "group0": [
> >             "host1",
> >             "host2"
> >         ],
> >         "group1": [
> >             "host3"
> >         ],
> >         "ungrouped": []  

If the hosts from 1st element of the list come to group0, from 2nd to
group1 and so on ... The play below

  vars:
    my_hosts:
      - ['host1', 'host2']
      - ['host3']
  tasks:
    - include_tasks: loop.yml
      loop: '{{ my_hosts }}'
      loop_control:
        loop_var: outer_item
        index_var: outer_idx
    - debug:
        var: groups

with this included task below gives the groups.

  $ cat loop.yml
  - add_host:
      name: "{{ item }}"
      groups: "{{ 'group' ~ outer_idx }}"
    loop: "{{ outer_item }}"


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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20190909144252.733260ea%40gmail.com.

Attachment: pgpzf5tyLtA3Z.pgp
Description: OpenPGP digital signature

Reply via email to