ansible-cmdb icon indicating copy to clipboard operation
ansible-cmdb copied to clipboard

support for ad-hoc groups created by the group_by module

Open divansantana opened this issue 6 years ago • 3 comments

Thanks for this great software.

We use group_by ansible module to create ad-hoc groups based on our custom facts. This creates ad-hoc groups like env_dev env_prod , os_el6 etc.

Is there is a way to get these groups to be detected in ansible-cmdb?

divansantana avatar Jul 30 '19 12:07 divansantana

Does the output of the following command include your ad-hoc groups?

ansible-inventory --list

If so, I'm thinking about rewriting the custom inventory parsing in ansible-cmdb to use the output of that command.

fboender avatar Jul 31 '19 05:07 fboender

Various local custom facts and other nice vars are in the output of that command.

Here some of my custom facts in the output:

"ansible_local": {
"custom": {
"country": "za",
"datacenter": "b1",
"dmz": "untrusted"
}

So we have a task something like this in our code:

- name: FACTS | Classify hosts depending on their OS distribution and version
  group_by:
    key: os_{{ ansible_facts['distribution'] }}{{ ansible_facts['distribution_major_version'] }}
  tags: facts

- name: FACTS | Classify hosts depending on their country
  group_by:
    key: country_{{ ansible_facts['ansible_local']['custom']['country'] }}
  tags: facts

This would create an ad-hoc group like os_CentOS7 or country_za during the playbook run.

It seems this data is not in the ansible-inventory output.

divansantana avatar Aug 06 '19 07:08 divansantana

There's an open PR (#215) that replaces the custom fact parser with ansible's default parser. I'm hoping this feature will be supported out of the box when I merge that PR.

I'll keep this issue open for now.

fboender avatar Sep 05 '21 07:09 fboender