inventory - support jinjia templating within network (#107)

Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
This commit is contained in:
Lukas Kämmerling 2021-08-25 10:57:03 +02:00 committed by GitHub
parent f1526285d8
commit 51865c29ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- inventory - support jinjia templating within `network`

View file

@ -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.")