Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not error in case of empty list/dict constructed group #53748

Merged
merged 1 commit into from
Mar 14, 2019

Conversation

AlanCoding
Copy link
Member

SUMMARY

I had a case where a constructed (keyed_group) was templating from a certain hostvar, and it produced an empty list. It produced an error that didn't make any sense. This adds content to the error message and makes this use case work successfully.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

constructed inventory plugin

ADDITIONAL INFORMATION

The error that my case produced, using devel, was:

 [WARNING]:  * Failed to parse /Users/alancoding/Documents/repos/ansible-inventory-file-examples/private/ec2/aws_ec2.yaml with auto plugin: No key or key resulted empty, invalid
entry

  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/inventory/manager.py", line 272, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/plugins/inventory/auto.py", line 58, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/plugins/inventory/aws_ec2.py", line 590, in parse
    self._populate(results, hostnames)
  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/plugins/inventory/aws_ec2.py", line 490, in _populate
    self._add_hosts(hosts=groups[group], group=group, hostnames=hostnames)
  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/plugins/inventory/aws_ec2.py", line 525, in _add_hosts
    self._add_host_to_keyed_groups(self.get_option('keyed_groups'), host, hostname, strict=strict)
  File "/Users/alancoding/Documents/repos/ansible/lib/ansible/plugins/inventory/__init__.py", line 432, in _add_host_to_keyed_groups
    raise AnsibleParserError("No key or key resulted empty, invalid entry")

In this case I was using tags.keys(), where the host variables had "tags": {}. It is going to be a problem if this case cannot be allowed to proceed.

Note: I only encountered this because I set strict: True, this allows users to be more vigilant, and I think it's a good idea to use this setting. However, it loses its utility if it fails the parsing process on cases it shouldn't.

Ping @bcoca @s-hertel

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. inventory Inventory category needs_triage Needs a first human triage before being processed. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels Mar 13, 2019
@AlanCoding AlanCoding changed the title Do not error in case of empty list constructed group Do not error in case of empty list/dict constructed group Mar 13, 2019
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Mar 13, 2019
@AlanCoding
Copy link
Member Author

For more background, I have isolated the host which returns "tags": {}

In the output from ec2.py, this host was a member of the tag_none group. That's a very non-standard syntax, so this will be produced via the compose groups, I'm still working on prototyping this. I'm 99% confident this will be created by another entry somewhere, and topic at issue here is to not error that host in the entry to create all the other tag group content.

@AlanCoding
Copy link
Member Author

I'm not sure why the test says that it didn't pass. It doesn't show any failures.

@AlanCoding
Copy link
Member Author

looks like it's good now

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 14, 2019
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Mar 14, 2019
@bcoca bcoca merged commit 8c2037a into ansible:devel Mar 14, 2019
@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. inventory Inventory category small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants