Re: [ansible-project] How to iterate over nested list and split it into two groups using add_host?
On Mon, 9 Sep 2019 00:05:26 -0700 (PDT) Danny Rehelis wrote: > vars: >my_hosts: > - ['host1', 'host2'] > - ['host3'] > [...] > loop: "{{ my_hosts }}" > [...] > ERROR! Unexpected Exception, this is probably a bug: unhashable type: 'list' > > I'm having hard time iterating this var in order to add_host properly into > X groups. I want this to be dynamic as much as possible. Flatten the lists. loop: "{{ my_hosts|flatten }}" 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/20190909092543.6569ea67%40gmail.com. pgpSQrhGnIV0f.pgp Description: OpenPGP digital signature
Re: [ansible-project] How to iterate over nested list and split it into two groups using add_host?
Thanks for the hint, Flatting the list results with TASK [print] ok: [localhost] => { "msg": { "all": [ "host1", "host2", "host3" ], "group0": [ "host1" ], "group1": [ "host2" ], "group2": [ "host3" ], "ungrouped": [] } } What i'm trying to achieve is - TASK [print] ok: [localhost] => { "msg": { "all": [ "host1", "host2", "host3" ], "group0": [ "host1", "host2" ], "group1": [ "host3" ], "ungrouped": [] } } On Monday, September 9, 2019 at 10:25:53 AM UTC+3, Vladimir Botka wrote: > > On Mon, 9 Sep 2019 00:05:26 -0700 (PDT) > Danny Rehelis > wrote: > > > vars: > >my_hosts: > > - ['host1', 'host2'] > > - ['host3'] > > [...] > > loop: "{{ my_hosts }}" > > [...] > > ERROR! Unexpected Exception, this is probably a bug: unhashable type: > 'list' > > > > I'm having hard time iterating this var in order to add_host properly > into > > X groups. I want this to be dynamic as much as possible. > > Flatten the lists. > > loop: "{{ my_hosts|flatten }}" > > 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/266cb5d1-6665-49c4-be1d-9f94429bcf00%40googlegroups.com.
Re: [ansible-project] How to iterate over nested list and split it into two groups using add_host?
On Mon, 9 Sep 2019 00:54:32 -0700 (PDT) Danny Rehelis 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": [] You've said "I want this to be dynamic as much as possible". Where does this "dynamic" assignment of the hosts to the groups come from? Any structure? If not it might be hard-coded i.e not dynamic at all. Make your choice. 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/20190909125237.11c3e648%40gmail.com. pgpyp6PMcisKX.pgp Description: OpenPGP digital signature
Re: [ansible-project] How to iterate over nested list and split it into two groups using add_host?
On Mon, 9 Sep 2019 12:52:37 +0200 Vladimir Botka wrote: > On Mon, 9 Sep 2019 00:54:32 -0700 (PDT) > Danny Rehelis 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. pgpzf5tyLtA3Z.pgp Description: OpenPGP digital signature