group_by adding all hosts?

Hi,

I’m pulling my hair out on this, but it’s probably something simple. I’m trying to create a dynamic group that has all our OpenVZ Guests in it.

So, in my ‘site.yml’ I have:

`

  • name: Setup Groups
    hosts: all
    tasks:
  • name: Create Groups based on OS
    group_by: key=dist_{{ ansible_distribution }}
  • name: Create VZ Guest Group
    group_by: key={{ ansible_virtualization_type }}-{{ ansible_virtualization_role }}
    `

My problem is, it seems to be putting every host in this group:

TASK: [Create VZ Guest Group] ************************************************* changed: [hostx.umaryland.edu] => {"changed": true, "groups": {"openvz-guest": ["hostx", "hosty", "hostz"]}}

‘hostz’ is definitely not a OpenVZ guest- in fact, if you run the ‘setup’ module against hostz, ‘ansible_virtualization_type’ and ‘ansible_virtualization_role’ aren’t even returned in the output.

For what it’s worth, I’m running ansible 1.4.3 from the EPEL repository.

What am I missing? I’m referencing:

https://github.com/ansible/ansible-examples/blob/master/language_features/group_by.yml

and

http://docs.ansible.com/group_by_module.html

Thanks,
Matt

I ran into odd issues when using group names with hyphens in them. Similar situation of not using variable names with hyphens in them. Not sure if this is the case but its worth mentioning.

Hi Brian,

Thanks for the tip. I actually tried changing the hyphen to an underscore, but no luck.

I think what’s happening is that on Linux systems that aren’t virtualized, the ‘ansible_virtualization_*’ facts aren’t getting set at all, so the grouping mechanism can’t handle it.

I’m thinking about submitting a patch in the ‘setup’ module that if it falls through to the end in Linux to set ‘ansible_virtualization_*’ to ‘NA’ like setup does for everything else it can’t figure out. Then, at least, non-virtual machines would be grouped into the ‘NA’ group, which is good enough for my purposes.

Matt