-
Notifications
You must be signed in to change notification settings - Fork 30
When creating dynamic inventory, jinja-expand tags, regions, and types. #747
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
base: dev
Are you sure you want to change the base?
Conversation
The tags, regions, and types filter array values are scanned, and any jinja templates are detected and expanded, just as is done already with the api_token. Resolves linode#746
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables Jinja template expansion for tags, regions, and types filter arrays in the dynamic inventory plugin, matching the existing template expansion behavior for api_token.
Changes:
- Added a helper function to expand Jinja templates in query option lists
- Applied template expansion to regions, types, and tags query options
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| items = [] | ||
| for item in query_list: | ||
| if self.templar.is_template(item): | ||
| items.append(self.templar.template(item, disable_lookups=False)) | ||
| else: | ||
| items.append(item) | ||
| return items |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The expand_templates function can be simplified using a list comprehension to improve readability and reduce boilerplate code.
| items = [] | |
| for item in query_list: | |
| if self.templar.is_template(item): | |
| items.append(self.templar.template(item, disable_lookups=False)) | |
| else: | |
| items.append(item) | |
| return items | |
| return [ | |
| self.templar.template(item, disable_lookups=False) | |
| if self.templar.is_template(item) | |
| else item | |
| for item in query_list | |
| ] |
| items = [] | ||
| for item in query_list: | ||
| if self.templar.is_template(item): | ||
| items.append(self.templar.template(item, disable_lookups=False)) |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting disable_lookups=False explicitly when it may already be the default could be misleading. Verify if this parameter needs to be specified, and if so, add a comment explaining why lookups should be enabled for these templates.
| items.append(self.templar.template(item, disable_lookups=False)) | |
| items.append( | |
| self.templar.template( | |
| item, | |
| # Intentionally enable lookups so inventory query | |
| # values can use Ansible lookup plugins (for example, | |
| # to pull regions/types/tags from external sources). | |
| disable_lookups=False, | |
| ) | |
| ) |
📝 Description
The tags, regions, and types filter array values are scanned, and any jinja templates are detected and expanded, just as is done already with the api_token.
Resolves #746
✔️ How to Test
The test case in #746 now works.