Skip to content

Conversation

@quale1
Copy link

@quale1 quale1 commented Apr 21, 2020

The parsing of group variables from inventory ini files doesn't do what Ansible documents or does. Ansible might not have documented this when the ansible-cmdb code was written, but the User Guide https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#inventory-basics-formats-hosts-and-groups says

Values passed in the INI format using the key=value syntax are interpreted differently depending on where they are declared:

When declared inline with the host, INI values are interpreted as Python literal structures (strings, numbers, tuples, lists, dicts, booleans, None). Host lines accept multiple key=value parameters per line. Therefore they need a way to indicate that a space is part of a value rather than a separator.

When declared in a :vars section, INI values are interpreted as strings. For example var=FALSE would create a string equal to ‘FALSE’. Unlike host lines, :vars sections accept only a single entry per line, so everything after the = must be the value for the entry.

So parsing a :vars section line doesn't need to try yaml or shlex tokenizing. Simply strip a trailing comment from the line if present, split on = and return the left and right parts as strings. The unspecified bit is what happens to leading and trailing whitespace on the left and right sides. Common practice in ini files is to strip whitespace, so that's what I did.

mgedmin added a commit to mgedmin/scripts that referenced this pull request Jun 8, 2021
@fboender fboender self-assigned this Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants