Skip to content

OpenNebula dynamic inventory plugin does not support keyed_groups #4497

Closed

Description

@bsanders

Summary

The documentation for the OpenNebula dynamic inventory plugin [0] refers to an option to created keyed_groups (because the documentation extends it).

    extends_documentation_fragment:
        - constructed

However, this functionality is not implemented. Even though the InventoryModule inherits from Constructable, self._add_host_to_keyed_groups() is never called.

[0] https://docs.ansible.com/ansible/latest/collections/community/general/opennebula_inventory.html

Issue Type

Bug Report

Component Name

opennebula dynamic inventory plugin

Ansible Version

$ ansible --version
ansible [core 2.12.4]
  config file = /code/rafiki/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vagrant/.pyenv/versions/3.10.3/lib/python3.10/site-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/vagrant/.pyenv/versions/3.10.3/bin/ansible
  python version = 3.10.3 (main, Apr  6 2022, 22:36:07) [GCC 11.2.0]
  jinja version = 3.1.1
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

# /home/vagrant/.pyenv/versions/3.10.3/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 4.7.0  

Configuration

$ ansible-config dump --only-changed
HOST_KEY_CHECKING(/code/rafiki/ansible.cfg) = False

OS / Environment

vagrant@ubuntu-jammy:/code/rafiki$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu Jammy Jellyfish (development branch)"

Steps to Reproduce

opennebula.yml:

plugin: community.general.opennebula
api_url: "RPC_URL"
# specify these here, or in the form username:password in ~/.one/one_auth or export ONE_AUTH=/some/other/path
#api_username:
#api_password:
keyed_groups:
  - prefix: distro
    key: ansible_distribution

ansible-inventory --list -i opennebula.yml

Expected Results

I expected a grouping of hosts by distribution. Note that the plugin does perform grouping by LABEL, which is seen below with the srv and foo labels/groups.

Actual Results

```console
ansible-inventory --list -i opennebula.yml
{
    "_meta": {
        "hostvars": {
            "terraform_demo_00": {
                "INFO": "",
                "INPUTS_ORDER": "",
                "LABELS": [],
                "LOGO": "images/logos/logo.png",
                "LXD_SECURITY_PRIVILEGED": "true",
                "MEMORY_UNIT_COST": "MB",
                "SCHED_REQUIREMENTS": "ARCH=\"x86_64\"",
                "ansible_host": "192.168.11.235",
                "name": "terraform_demo_00",
                "v4_first_ip": "192.168.11.235",
                "v6_first_ip": false
            },
            "terraform_demo_01": {
                "INFO": "",
                "INPUTS_ORDER": "",
                "LABELS": [
                    "srv",
                    "foo"
                ],
                "LOGO": "images/logos/logo.png",
                "LXD_SECURITY_PRIVILEGED": "true",
                "MEMORY_UNIT_COST": "MB",
                "SCHED_REQUIREMENTS": "ARCH=\"x86_64\"",
                "ansible_host": "192.168.11.241",
                "name": "terraform_demo_01",
                "v4_first_ip": "192.168.11.241",
                "v6_first_ip": false
            }
        }
    },
    "all": {
        "children": [
            "srv",
            "foo",
            "ungrouped"
        ]
    },
    "srv": {
        "hosts": [
            "terraform_demo_01"
        ]
    },
    "foo": {
        "hosts": [
            "terraform_demo_01"
        ]
    },
    "ungrouped": {
        "hosts": [
            "terraform_demo_00"
        ]
    }
}


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct

Activity

  1. ansibullbot commented on Apr 12, 2022

    @ansibullbot
  2. bsanders commented on Apr 12, 2022

    @bsanders
    ContributorAuthor

    !component =plugins/inventory/opennebula.py

  3. ansibullbot commented on Apr 12, 2022

    @ansibullbot
    Collaborator

    Files identified in the description:

    If these files are incorrect, please update the component name section of the description or use the !component bot command.

    click here for bot help

  4. ansibullbot commented on Apr 12, 2022

    @ansibullbot
    Collaborator
  5. feldsam commented on Apr 12, 2022

    @feldsam
    Contributor

    Hi @bsanders , I don;t know how keyed groups work on backgroud, would you share xcepted result as json code? From what variables you want to get distribution? I don't see it in opennebula user template

  6. bsanders commented on Apr 12, 2022

    @bsanders
    ContributorAuthor

    I was not super clear on how the ansible_distribution was supposed to turn into keyed_groups either. I was looking at this [0], specifically the "examples". I guess I was assuming ansible would reach out to get the facts, including distro, then sort things into groups. But that wasn't happening.

    To figure out what actually happens, I hacked the plugin and I've stepped through the code with pdb. With my changes, I'm able to say keyed_groups: key:some_opennebula_attribute and it works. Not sure if key: ansible_distribution is supposed to work or not.

    Would you be willing to look at a PR to add this functionality? I may attempt to implement the other Constructable features, though I'm not sure I'll need them myself.

    [0] https://docs.ansible.com/ansible/latest/collections/ansible/builtin/constructed_inventory.html

  7. felixfontein commented on Apr 13, 2022

    @felixfontein
    Collaborator

    This isn't a bug report, but a feature request. Inventory plugins have to opt-in to support keyed groups (and similar features).

  8. added
    featureThis issue/PR relates to a feature request
    and removed
    bugThis issue/PR relates to a bug
    on Apr 13, 2022
  9. bsanders commented on Apr 13, 2022

    @bsanders
    ContributorAuthor

    The current documentation for the plugin says it supports it, but it's not implemented. I spent an hour trying to figure out what I was doing wrong before looking at the code and realizing it just wasn't implemented.

  10. feldsam commented on Apr 13, 2022

    @feldsam
    Contributor

    This is bug in documentation. So we can fix it, but how, when it is extended?

  11. felixfontein commented on Apr 13, 2022

    @felixfontein
    Collaborator

    Ah, I completely missed the extends_documentation_fragment. Sorry.

  12. added
    bugThis issue/PR relates to a bug
    and removed
    featureThis issue/PR relates to a feature request
    on Apr 13, 2022
  13. felixfontein commented on Apr 13, 2022

    @felixfontein
    Collaborator
  14. bsanders commented on Apr 13, 2022

    @bsanders
    ContributorAuthor

    I have the code working. Currently looking into adding some unit tests.

  15. bsanders commented on Apr 18, 2022

    @bsanders
    ContributorAuthor

    I opened a PR; code is working, some test logic is failing (traceback in PR). If anyone watching knows why the 'InventoryModule' object has no attribute 'templar' in the test, I'm all ears.

  16. added a commit that references this issue on May 14, 2022
  17. added a commit that references this issue on May 11, 2026
  18. added a commit that references this issue on May 14, 2026
  19. added a commit that references this issue on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue/PR relates to a bughas_prinventoryinventory plugin

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions