a )g&@sddlmZmZmZeZddlZddlZddlZddl Z ddl m Z ddl mZddlmZmZmZmZddlmZmZmZddlmZddlmZdd lmZdd lmZm Z Gd d d eZ!dS) )absolute_importdivisionprint_functionN) constants) ensure_type) AnsibleErrorAnsibleFileNotFound AnsibleActionAnsibleActionFail)to_bytesto_text to_native)boolean) string_types) ActionBase)generate_ansible_template_varsAnsibleEnvironmentcs&eZdZdZdZdfdd ZZS) ActionModuleT Nc's|durt}tt|||}~dD]T}||jjvr&t|jj|d}|durnt|tsnt d|t |f||jj|<q&zLt |jj dddd}t |jj dd dd}t |jj d ddd}Wn0t y} zt t| WYd} ~ n d} ~ 00|jj d d} |jj d d} |jj d d} |jj d|j} |jj dd}|jj dd}|jj dd}|jj dd}|jj dd}|jj dd}|jj ddpd}gd}gd}| |vr||| } zz| durt dnv| dus | durt dnX| |vr(t dnDz|d| } Wn2tyj} zt t| WYd} ~ n d} ~ 00|jj dd}|dkrdtt| j}z|j| }Wn:ty} z t d | t| fWYd} ~ n d} ~ 00t|d!d"}z|zt|d#B}zt|d!d"}Wnty8t d$Yn0Wdn1sP0Y| d%g}||jj tj!"| gg}|D]$}|#tj!$|d|#|q|}|%}|&t'|jj d d| | |j(j)t*|| |||||||||d& } | j+|d dd'}!WnTt,y$Yn@t-yb} z&t d(t | j.t| fWYd} ~ n d} ~ 00W|j/|n|j/|0|j%}"||"jd<d)D]}#|"j0|#dqt1j2t3j4d*}$ztj!$|$tj!5| }%tt|%d!d"d+$}|6t|!|d!d,Wdn1s0Y|"j&t|%| |d-|j7j8j d.|"|j9|j:|j|j(|j7d/}&|&|&j|d0Wt;|j9j?j@n|>|j9j?j@0|S)1z! handler for template operations N) srcdeststatenewline_sequencevariable_start_stringvariable_end_stringblock_start_stringblock_end_stringcomment_start_stringcomment_end_stringstringz1%s is expected to be a string, but got %s insteadfollowF)strict trim_blocksT lstrip_blocksrrrrrrrrrroutput_encodingzutf-8)z\nz\rz\r\n)r z z)'state' cannot be specified on a templatezsrc and dest are requiredz/newline_sequence needs to be one of: , or Z templatesmodeZpreservez0%03ozcould not find src=%s, %sZsurrogate_or_strict)errorsrbz+Template source files must be utf-8 encodedZansible_search_path) Zenvironment_class searchpathrrrrrrrr"r#Zavailable_variables)Zpreserve_trailing_newlinesZescape_backslashesz%s: %s) rrrrrrrr"r#r$)dirwb)encodingr')rrr zansible.legacy.copy)ZtaskZ connectionZ play_contextloadertemplarZshared_loader_obj) task_vars)AdictsuperrrunZ_taskargsr isinstancerr typerget TypeErrorr DEFAULT_NEWLINE_SEQUENCEindexZ _find_needlerr statS_IMODEosst_modeZ_loaderZ get_real_filerr openread UnicodeErrorextendZ_basedirpathdirnameappendjoincopyupdaterZ_templarZcopy_with_new_envrZ do_templater Exception__name__Zcleanup_tmp_filepoptempfileZmkdtempCZDEFAULT_LOCAL_TMPbasenamewriteZ_shared_loader_objZ action_loaderZ _connectionZ _play_contextshutilrmtreeresultZ_remove_tmp_pathZ_shellZtmpdir)'selftmpr/rQZs_typevaluer r"r#esourcerrrrrrrrrr$Zwrong_sequencesZallowed_sequencesr&Z tmp_sourceZ b_tmp_sourcefZ template_datar)Z newsearchpathpZ temp_varsr.Z resultantZnew_taskremoveZ local_tempdirZ result_fileZ copy_action __class__C/usr/lib/python3.9/site-packages/ansible/plugins/action/template.pyr2s "      " *  .  2  4 ,$$zActionModule.run)NN)rI __module__ __qualname__ZTRANSFERS_FILESr8r2 __classcell__r\r\rZr]rsr)"Z __future__rrrr5Z __metaclass__r<rOr:rKZansiblerrLZansible.config.managerrZansible.errorsrrr r Zansible.module_utils._textr r r Z)ansible.module_utils.parsing.convert_boolrZansible.module_utils.sixrZansible.plugins.actionrZansible.templaterrrr\r\r\r]s