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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to