I'm not positive group_by can be used with with_items.

I think we may have proposed making this raise an error, which seems easy
to do if this is the case.

If you feel you can boil this down to a minimal reproducer example please
file a bug in github and we can take a look.   I'd probably just do it with
a hard coded list for starters, just to make sure variables have nothing to
do with it (as it would provide more information if they did).

Sidenote - it's very unusual to put variables below your tasks section.
 I'd suggest not doing that as it makes playbooks less readable.




On Fri, May 23, 2014 at 6:06 AM, Joost Cassee <[email protected]> wrote:

> Hi,
>
> I have a couple of hosts that have a 'profiles' variable that contains a
> list of, well, profiles that I want to apply. I want to use group_by to
> turn those into groups. However, it is not working. (I am doing this on the
> current devel branch, by the way.)
>
> This test case isolates the issue:
>
> hosts
> -----
> host1
> host2
>
> test.yml
> --------
> - hosts: all
>   connection: local
>   gather_facts: no
>   tasks:
>   - debug: var=test_items
>   - group_by: key=host_{{ item }}
>     with_items: test_items
>   - debug: var=group_names
>   vars:
>     test_items:
>     - "{{ inventory_hostname }}"
>
> $ ansible-playbook test.yml -i hosts
>
> PLAY [all]
> ********************************************************************
>
> TASK: [debug var=test_items]
> **************************************************
> ok: [host2] => {
>     "test_items": [
>         "host2"
>     ]
> }
> ok: [host1] => {
>     "test_items": [
>         "host1"
>     ]
> }
>
> TASK: [group_by key=host_{{item}}]
> ********************************************
> changed: [host1] => (item=host1)
>
> TASK: [debug var=group_names]
> *************************************************
> ok: [host1] => {
>     "group_names": [
>         "host_host1",
>         "ungrouped"
>     ]
> }
> ok: [host2] => {
>     "group_names": [
>         "host_host1",
>         "ungrouped"
>     ]
> }
>
> PLAY RECAP
> ********************************************************************
> host1                      : ok=3    changed=1    unreachable=0
> failed=0
> host2                      : ok=3    changed=1    unreachable=0
> failed=0
>
> Notice how both hosts are in group 'host_host1', even host2.
>
> Is this expected behavior (i.e. does group_by not work with with_items) or
> should I create an issue on GitHub?
>
> Regards,
> Joost
>
> --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/b2ff3403-a35a-4858-ba27-1836f28ea136%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/b2ff3403-a35a-4858-ba27-1836f28ea136%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgxCSwe_q6wyAYM8O6a6Dzt2%2BVapOW_0uBok_3jBKiJUjw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to