Repository navigation
Closed
Labels
bugThis issue/PR relates to a bugThis issue/PR relates to a bughas_prinventoryinventory plugininventory plugin
Description
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
Metadata
Metadata
Assignees
Labels
bugThis issue/PR relates to a bugThis issue/PR relates to a bughas_prinventoryinventory plugininventory plugin
Activity
ansibullbot commentedon Apr 12, 2022
bsanders commentedon Apr 12, 2022
!component =plugins/inventory/opennebula.py
ansibullbot commentedon Apr 12, 2022
Files identified in the description:
plugins/inventory/opennebula.pyIf these files are incorrect, please update the
component namesection of the description or use the!componentbot command.click here for bot help
ansibullbot commentedon Apr 12, 2022
cc @feldsam
click here for bot help
feldsam commentedon Apr 12, 2022
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
bsanders commentedon Apr 12, 2022
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_attributeand it works. Not sure ifkey: ansible_distributionis 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
Constructablefeatures, though I'm not sure I'll need them myself.[0] https://docs.ansible.com/ansible/latest/collections/ansible/builtin/constructed_inventory.html
felixfontein commentedon Apr 13, 2022
This isn't a bug report, but a feature request. Inventory plugins have to opt-in to support keyed groups (and similar features).
bsanders commentedon Apr 13, 2022
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.
feldsam commentedon Apr 13, 2022
This is bug in documentation. So we can fix it, but how, when it is extended?
felixfontein commentedon Apr 13, 2022
Ah, I completely missed the
extends_documentation_fragment. Sorry.felixfontein commentedon Apr 13, 2022
@feldsam basically what you need to do is: https://github.com/ansible-collections/community.general/blob/main/plugins/inventory/nmap.py#L86-L93
bsanders commentedon Apr 13, 2022
I have the code working. Currently looking into adding some unit tests.
bsanders commentedon Apr 18, 2022
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.ansible: updated to 5.7.1
ansible: updated to 5.7.1
ansible: updated to 5.7.1
ansible: updated to 5.7.1