From 36519ff95eddea72d7c16f9a7c3e8501ee0ab60e Mon Sep 17 00:00:00 2001 From: Mark Mercado Date: Wed, 19 Jan 2022 10:49:50 -0500 Subject: [PATCH] Parameterize disable_lookups (#76770) Allow inventory plugins to enable/disable lookups in the compose templating --- .../76769-inventory-constructable-disable-lookups.yml | 2 ++ lib/ansible/plugins/inventory/__init__.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/76769-inventory-constructable-disable-lookups.yml diff --git a/changelogs/fragments/76769-inventory-constructable-disable-lookups.yml b/changelogs/fragments/76769-inventory-constructable-disable-lookups.yml new file mode 100644 index 00000000000..30f0a4b9689 --- /dev/null +++ b/changelogs/fragments/76769-inventory-constructable-disable-lookups.yml @@ -0,0 +1,2 @@ +bugfixes: + - inventory - parameterize ``disable_lookups`` in ``Constructable`` (https://github.com/ansible/ansible/issues/76769). diff --git a/lib/ansible/plugins/inventory/__init__.py b/lib/ansible/plugins/inventory/__init__.py index 4af4e2d2038..299245298d3 100644 --- a/lib/ansible/plugins/inventory/__init__.py +++ b/lib/ansible/plugins/inventory/__init__.py @@ -332,7 +332,7 @@ class Cacheable(object): class Constructable(object): - def _compose(self, template, variables): + def _compose(self, template, variables, disable_lookups=True): ''' helper method for plugins to compose variables for Ansible based on jinja2 expression and inventory vars''' t = self.templar @@ -346,7 +346,8 @@ class Constructable(object): else: t.available_variables = variables - return t.template('%s%s%s' % (t.environment.variable_start_string, template, t.environment.variable_end_string), disable_lookups=True) + return t.template('%s%s%s' % (t.environment.variable_start_string, template, t.environment.variable_end_string), + disable_lookups=disable_lookups) def _set_composite_vars(self, compose, variables, host, strict=False): ''' loops over compose entries to create vars for hosts '''