Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions plugins/inventory/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ def _get_query_options(
self, config_data: Dict[str, Any]
) -> Tuple[Any, Any, Any]:
"""Get user specified query options from the configuration."""

def expand_templates(query_list: List[str]) -> List[str]:
items = []
for item in query_list:
if self.templar.is_template(item):
items.append(self.templar.template(item, disable_lookups=False))
Copy link

Copilot AI Jan 22, 2026

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.

Suggested change
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,
)
)

Copilot uses AI. Check for mistakes.
else:
items.append(item)
return items
Comment on lines +247 to +253
Copy link

Copilot AI Jan 22, 2026

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.

Suggested change
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
]

Copilot uses AI. Check for mistakes.

options = {
"regions": {
"type_to_be": list,
Expand All @@ -259,9 +269,9 @@ def _get_query_options(
name, options[name]["type_to_be"], options[name]["value"]
)

regions = options["regions"]["value"]
types = options["types"]["value"]
tags = options["tags"]["value"]
regions = expand_templates(options["regions"]["value"])
types = expand_templates(options["types"]["value"])
tags = expand_templates(options["tags"]["value"])

return regions, types, tags

Expand Down