a ì)gNã@s®ddlmZmZmZeZdZdZdZddl m Z ddl Z ddl m ZddlmZddlmZdd lmZmZdd lmZmZdd lmZdd lmZeƒZGd d„deƒZdS)é)Úabsolute_importÚdivisionÚprint_functiona­ 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 comment_end_string: description: The string marking the end of a comment statement. version_added: '2.12' type: str 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_bytesÚto_text)Úgenerate_ansible_template_varsÚAnsibleEnvironment)ÚDisplay)ÚNativeJinjaTextc@seZdZdd„ZdS)Ú LookupModulec KsÊg}|j||d| d¡}| d¡}| d¡o4tj}| d¡}| d¡} | d¡} | d¡} |rj|j} n|jjtd } |D]F} t d | ¡|  |d | ¡}t  d |¡|r¸|j   |¡\}}t |d d}| dg¡}|rg}|D]"}| tj |d ¡¡| |¡qè|}| dtj |¡¡t|ƒ}| t| |ƒ¡| |¡| j|| | | ||d"| j|d|dd}Wdƒn1s†0Ytjrž|r¤|s¬t|ƒ}| |¡q|td| ƒ‚q||S)N)Z var_optionsZdirectÚ convert_dataZ template_varsÚ jinja2_nativeÚvariable_start_stringÚvariable_end_stringÚcomment_start_stringÚcomment_end_string)Zenvironment_classzFile lookup term: %sZ templateszFile lookup using %s as fileZsurrogate_or_strict)ÚerrorsZansible_search_pathr)rrrrZavailable_variablesÚ searchpathTF)Zpreserve_trailing_newlinesrZescape_backslashesz6the template file %s could not be found for the lookup)Z set_optionsZ get_optionÚCZDEFAULT_JINJA2_NATIVEZ_templarZcopy_with_new_envr ÚdisplayÚdebugZfind_file_in_search_pathZvvvvZ_loaderZ_get_file_contentsr ÚgetÚappendÚosÚpathÚjoinÚinsertÚdirnamerÚupdater Zset_temporary_contextÚtemplater r)ÚselfZtermsZ variablesÚkwargsÚretZconvert_data_pZlookup_template_varsrrrrrZtemplarZtermZ lookupfileZb_template_dataZ show_dataZ template_datarZ newsearchpathÚpÚvarsÚres©r)úC/usr/lib/python3.9/site-packages/ansible/plugins/lookup/template.pyÚrunbsX           üÿ& zLookupModule.runN)Ú__name__Ú __module__Ú __qualname__r+r)r)r)r*r`sr)Z __future__rrrÚtypeZ __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNÚcopyrrZansible.constantsZ constantsrZansible.errorsrZansible.plugins.lookuprZansible.module_utils._textrr Zansible.templater r Zansible.utils.displayr Zansible.utils.native_jinjar rrr)r)r)r*Ús3