diff --git a/changelogs/fragments/7996-Add templating support to Icinga2 Inventory.yml b/changelogs/fragments/7996-Add templating support to Icinga2 Inventory.yml new file mode 100644 index 0000000000..9998583b83 --- /dev/null +++ b/changelogs/fragments/7996-Add templating support to Icinga2 Inventory.yml @@ -0,0 +1,2 @@ +minor_changes: + - icinga2 inventory plugin - add Jinja2 templating support to ``url``, ``user``, and ``password`` paramenters (https://github.com/ansible-collections/community.general/issues/7074, https://github.com/ansible-collections/community.general/pull/7996). \ No newline at end of file diff --git a/plugins/inventory/icinga2.py b/plugins/inventory/icinga2.py index 1c67ea3237..a418707332 100644 --- a/plugins/inventory/icinga2.py +++ b/plugins/inventory/icinga2.py @@ -277,12 +277,22 @@ class InventoryModule(BaseInventoryPlugin, Constructable): self._read_config_data(path) # Store the options from the YAML file - self.icinga2_url = self.get_option('url').rstrip('/') + '/v1' + self.icinga2_url = self.get_option('url') self.icinga2_user = self.get_option('user') self.icinga2_password = self.get_option('password') self.ssl_verify = self.get_option('validate_certs') self.host_filter = self.get_option('host_filter') self.inventory_attr = self.get_option('inventory_attr') + + if self.templar.is_template(self.icinga2_url): + self.icinga2_url = self.templar.template(variable=self.icinga2_url, disable_lookups=False) + if self.templar.is_template(self.icinga2_user): + self.icinga2_user = self.templar.template(variable=self.icinga2_user, disable_lookups=False) + if self.templar.is_template(self.icinga2_password): + self.icinga2_password = self.templar.template(variable=self.icinga2_password, disable_lookups=False) + + self.icinga2_url = self.icinga2_url.rstrip('/') + '/v1' + # Not currently enabled # self.cache_key = self.get_cache_key(path) # self.use_cache = cache and self.get_option('cache')