mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Add support for variable_{start,end}_string (#49711)
Template lookup plugin now support variable_start_string and variable_end_string, just like template module. Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
30c611a9cf
commit
e464c543f6
4 changed files with 46 additions and 40 deletions
|
@ -1,9 +1,7 @@
|
|||
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
# (c) 2012-17 Ansible Project
|
||||
# Copyright: (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
# Copyright: (c) 2012-17, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
@ -13,18 +11,33 @@ DOCUMENTATION = """
|
|||
version_added: "0.9"
|
||||
short_description: retrieve contents of file after templating with Jinja2
|
||||
description:
|
||||
- this is mostly a noop, to be used as a with_list loop when you dont want the content transformed in any way.
|
||||
- this is mostly a noop, to be used as a with_list loop when you do not want the content transformed in any way.
|
||||
options:
|
||||
_terms:
|
||||
description: list of files to template
|
||||
convert_data:
|
||||
type: bool
|
||||
description: whether to convert YAML into data. If False, strings that are YAML will be left untouched.
|
||||
variable_start_string:
|
||||
description: The string marking the beginning of a print statement.
|
||||
default: '{{'
|
||||
version_added: '2.8'
|
||||
type: str
|
||||
variable_end_string:
|
||||
description: The string marking the end of a print statement.
|
||||
default: '}}'
|
||||
version_added: '2.8'
|
||||
type: str
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: show templating results
|
||||
debug: msg="{{ lookup('template', './some_template.j2') }}
|
||||
debug:
|
||||
msg: "{{ lookup('template', './some_template.j2') }}"
|
||||
|
||||
- name: show templating results with different variable start and end string
|
||||
debug:
|
||||
msg: "{{ lookup('template', './some_template.j2', variable_start_string='[%', variable_end_string='%]') }}"
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
|
@ -51,6 +64,9 @@ class LookupModule(LookupBase):
|
|||
lookup_template_vars = kwargs.get('template_vars', {})
|
||||
ret = []
|
||||
|
||||
variable_start_string = kwargs.get('variable_start_string', None)
|
||||
variable_end_string = kwargs.get('variable_end_string', None)
|
||||
|
||||
for term in terms:
|
||||
display.debug("File lookup term: %s" % term)
|
||||
|
||||
|
@ -74,6 +90,10 @@ class LookupModule(LookupBase):
|
|||
else:
|
||||
searchpath = [self._loader._basedir, os.path.dirname(lookupfile)]
|
||||
self._templar.environment.loader.searchpath = searchpath
|
||||
if variable_start_string is not None:
|
||||
self._templar.environment.variable_start_string = variable_start_string
|
||||
if variable_end_string is not None:
|
||||
self._templar.environment.variable_end_string = variable_end_string
|
||||
|
||||
# The template will have access to all existing variables,
|
||||
# plus some added by ansible (e.g., template_{path,mtime}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue