Skip to content

Commit 2a62edc

Browse files
authored
nb_inventory - Allow Jinja2 template on filter (#834)
* allow jinja2 on filter
1 parent 50a271b commit 2a62edc

19 files changed

+5763
-7
lines changed

changelogs/fragments/allow-jinja2.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- nb_inventory - Allow Jinja2 template on filter

plugins/inventory/nb_inventory.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,21 @@
176176
type: boolean
177177
version_added: "0.2.0"
178178
query_filters:
179-
description: List of parameters passed to the query string for both devices and VMs (Multiple values may be separated by commas)
179+
description:
180+
- List of parameters passed to the query string for both devices and VMs (Multiple values may be separated by commas).
181+
- You can also use Jinja2 templates.
180182
type: list
181183
default: []
182184
device_query_filters:
183-
description: List of parameters passed to the query string for devices (Multiple values may be separated by commas)
185+
description:
186+
- List of parameters passed to the query string for devices (Multiple values may be separated by commas).
187+
- You can also use Jinja2 templates.
184188
type: list
185189
default: []
186190
vm_query_filters:
187-
description: List of parameters passed to the query string for VMs (Multiple values may be separated by commas)
191+
description:
192+
- List of parameters passed to the query string for VMs (Multiple values may be separated by commas).
193+
- You can also use Jinja2 templates.
188194
type: list
189195
default: []
190196
timeout:
@@ -1941,6 +1947,7 @@ def parse(self, inventory, loader, path, cache=True):
19411947
super(InventoryModule, self).parse(inventory, loader, path)
19421948
self._read_config_data(path=path)
19431949
self.use_cache = cache
1950+
self.templar.available_variables = self._vars
19441951

19451952
# NetBox access
19461953
token = self.templar.template(self.get_option("token"), fail_on_undefined=False)
@@ -1974,9 +1981,13 @@ def parse(self, inventory, loader, path, cache=True):
19741981
# Filter and group_by options
19751982
self.group_by = self.get_option("group_by")
19761983
self.group_names_raw = self.get_option("group_names_raw")
1977-
self.query_filters = self.get_option("query_filters")
1978-
self.device_query_filters = self.get_option("device_query_filters")
1979-
self.vm_query_filters = self.get_option("vm_query_filters")
1984+
self.query_filters = self.templar.template(self.get_option("query_filters"))
1985+
self.device_query_filters = self.templar.template(
1986+
self.get_option("device_query_filters")
1987+
)
1988+
self.vm_query_filters = self.templar.template(
1989+
self.get_option("vm_query_filters")
1990+
)
19801991
self.virtual_chassis_name = self.get_option("virtual_chassis_name")
19811992
self.dns_name = self.get_option("dns_name")
19821993
self.ansible_host_dns_name = self.get_option("ansible_host_dns_name")

0 commit comments

Comments
 (0)