From 51865c29ab306b60be88963e81687761260eae4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Wed, 25 Aug 2021 10:57:03 +0200 Subject: [PATCH] inventory - support jinjia templating within `network` (#107) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Kämmerling --- changelogs/fragments/inventory-network-templating.yml | 2 ++ plugins/inventory/hcloud.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/inventory-network-templating.yml diff --git a/changelogs/fragments/inventory-network-templating.yml b/changelogs/fragments/inventory-network-templating.yml new file mode 100644 index 0000000..084ad8e --- /dev/null +++ b/changelogs/fragments/inventory-network-templating.yml @@ -0,0 +1,2 @@ +minor_changes: + - inventory - support jinjia templating within `network` diff --git a/plugins/inventory/hcloud.py b/plugins/inventory/hcloud.py index a683245..be35e2d 100644 --- a/plugins/inventory/hcloud.py +++ b/plugins/inventory/hcloud.py @@ -142,10 +142,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable): def _filter_servers(self): if self.get_option("network"): + network = self.templar.template(self.get_option("network"), fail_on_undefined=False) or self.get_option("network") try: - self.network = self.client.networks.get_by_name(self.get_option("network")) + self.network = self.client.networks.get_by_name(network) if self.network is None: - self.network = self.client.networks.get_by_id(self.get_option("network")) + self.network = self.client.networks.get_by_id(network) except APIException: raise AnsibleError( "The given network is not found.")