When creating dynamic inventory, jinja-expand tags, regions, and types.#747
When creating dynamic inventory, jinja-expand tags, regions, and types.#747brad2014 wants to merge 1 commit intolinode:devfrom
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.
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 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.