o nnh@sddlmZdZdZdZddlmZddlZddlm Z ddl m Z ddl mZdd lmZdd lmZmZdd lmZdd lmZeZGd ddeZdS)) annotationsaF name: template author: Michael DeHaan version_added: "0.9" short_description: retrieve contents of file after templating with Jinja2 description: - Returns a list of strings; for each template in the list of templates you pass in, returns a string containing the results of processing that template. 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. - Mutually exclusive with the jinja2_native option. default: true 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 jinja2_native: description: - Controls whether to use Jinja2 native types. - It is off by default even if global jinja2_native is True. - Has no effect if global jinja2_native is False. - This offers more flexibility than the template module which does not use Jinja2 native types at all. - Mutually exclusive with the convert_data option. default: False version_added: '2.11' type: bool template_vars: description: A dictionary, the keys become additional variables available for templating. default: {} version_added: '2.3' type: dict comment_start_string: description: The string marking the beginning of a comment statement. version_added: '2.12' type: str default: '{#' comment_end_string: description: The string marking the end of a comment statement. version_added: '2.12' type: str default: '#}' seealso: - ref: playbook_task_paths description: Search paths used for relative templates. aO - name: show templating results ansible.builtin.debug: msg: "{{ lookup('ansible.builtin.template', './some_template.j2') }}" - name: show templating results with different variable start and end string ansible.builtin.debug: msg: "{{ lookup('ansible.builtin.template', './some_template.j2', variable_start_string='[%', variable_end_string='%]') }}" - name: show templating results with different comment start and end string ansible.builtin.debug: msg: "{{ lookup('ansible.builtin.template', './some_template.j2', comment_start_string='[#', comment_end_string='#]') }}" zW _raw: description: file(s) content after templating type: list elements: raw )deepcopyN) AnsibleError) LookupBase)to_text)generate_ansible_template_varsAnsibleEnvironment)Display)NativeJinjaTextc@seZdZddZdS) LookupModulec Ksg}|j||d|d}|d}|dotj}|d}|d} |d} |d} |r5|j} n|jjtd } |D]} td | | |d | }t d ||r|j |\}}t |d d}|dg}|rg}|D]}|tj|d ||qq|}|dtj|t|}|t| |||| j||dt|| | | d}| j|d|d|d}Wdn1swYtjr|r|st|}||q>td| |S)N) var_optionsdirect convert_data template_vars jinja2_nativevariable_start_stringvariable_end_stringcomment_start_stringcomment_end_string)environment_classzFile lookup term: %s templateszFile lookup using %s as filesurrogate_or_strict)errorsansible_search_pathr)available_variables searchpath)rrrrTF)preserve_trailing_newlinesrescape_backslashes overridesz6the template file %s could not be found for the lookup) set_options get_optionCDEFAULT_JINJA2_NATIVE_templarcopy_with_new_envrdisplaydebugfind_file_in_search_pathvvvv_loader_get_file_contentsrgetappendospathjoininsertdirnamerupdaterset_temporary_contextdicttemplater r)selfterms variableskwargsretconvert_data_plookup_template_varsrrrrrtemplarterm lookupfileb_template_data show_data template_datar newsearchpathpvarsrresrGJ/usr/local/lib/python3.10/dist-packages/ansible/plugins/lookup/template.pyrunfs^             zLookupModule.runN)__name__ __module__ __qualname__rIrGrGrGrHr ds r ) __future__r DOCUMENTATIONEXAMPLESRETURNcopyrr-ansible.constants constantsr!ansible.errorsransible.plugins.lookupr+ansible.module_utils.common.text.convertersransible.templaterransible.utils.displayr ansible.utils.native_jinjar r%r rGrGrGrHs 8