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

Validate inventory file (#662) #1182

Draft
wants to merge 4 commits into
base: 3.x
Choose a base branch
from

Conversation

simonhammes
Copy link
Contributor

No description provided.

@@ -258,7 +270,7 @@ def make_inventory_from_files(
for hosts in groups.values():
# Groups can be a list of hosts or tuple of (hosts, data)
hosts = _get_any_tuple_first(hosts)

# TODO: Generator expressions are silently discarded (?)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look at this.


return all(isinstance(item, ALLOWED_HOST_TYPES) for item in value)
if not all(isinstance(item, ALLOWED_HOST_TYPES) for item in value):
logger.warning('Ignoring host group "%s". Host groups may only contain strings (host) or tuples (host, data).', key)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an error instead?

On one hand, an inventory file might contain other data structures since you can do whatever you want in an inventory file (similar to dynamic inventory in Ansible), so even this warning might be too verbose?

On the other hand, silently ignoring variables due to invalid types is also problematic (see #662).

Any thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think warning is the correct behavior for now - don't want to break anything existing but also need the warning so at least people will know!

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great so far, thank you @simonhammes!

I think long term pyinfra should be moving towards inventory functions as the default to avoid the weird "list or tuple" thing for hosts/groups.

There's also potential for a DSL kind of inventory, but that's a future problem :)

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