Open kaharlichenko opened 1 year ago
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.
cc @mattclay click here for bot help
!component =plugins/inventory/lxd.py
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.
cc @conloos click here for bot help
Maybe it's better to remove the valiation completely? In any case, if it is changed, it needs to accept the names it accepted before (even though it also accepted pretty strange ones).
it needs to accept the names it accepted before (even though it also accepted pretty strange ones)
There's no guarantee that ansible itself will work well with "strange" names, so I believe it would be safe to forbid them.
As for allowing the new "good" ones it should be safe as well, since they are "good" by definition :)
On the other hand, it might be a good idea to be consistent with the rest of the community inventory plugins: if nobody does any validation, then maybe it's reasonable to drop it here too.
Another option might be using some kind of validate_variable_name
function from ansible-core
itself, provided such a function exists. I'm not that familiar with the code base.
ansible-core does some validation and allows sanitization of group names itself, see https://docs.ansible.com/ansible/latest/reference_appendices/config.html#transform-invalid-group-chars. I don't think it is a good idea to repeat this in all kind of different manners in all inventory plugins.
Summary
I'm trying to set up my own home lab Kubernetes cluster using playbooks from amazing Kubespray project.
The aforementioned playbooks heavily rely on group names containing underscores like
kube_node
,kube_control_plane
, etc. Alas, when trying to build the dynamic inventory with the lxd inventory plugin I get crashes due to the group name validation.According to Inventory basics: formats, hosts, and groups:
From Creating valid variable names we can learn that:
That makes me think that both
kube_node
andkube_control_plane
should be accepted as valid group names.I believe the culprit resides here: https://github.com/ansible-collections/community.general/blob/42f7531f212c6401ca351de62bde0369916d8e58/plugins/inventory/lxd.py#L978-L982
isalnum
gives both false negative and false positive validation results as can be seen below:I suggest changing the validation to something like this:
This is still not ideal as it doesn't filter out neither Python nor Ansible keywords, but at least it one step closer to the variable definition from the docs.
Issue Type
Bug Report
Component Name
lxd
Ansible Version
Community.general Version
Configuration
OS / Environment
Steps to Reproduce
Given the
hosts-lxd.yml
inventory file with the following contents:When I try to list the dynamic inventory with
ansible-inventory --inventory hosts-lxd.yml --list
I got a crash due to the group name validation. If I changekube_node
tokubenode
in the yaml file above everything works like a charm.Expected Results
A proper dynamic inventory is expected to be built from the introspection of the LXD server instance. The group names must have underscores included in them.
Actual Results
Code of Conduct