a )g99@sddlmZmZmZeZddlZddlZddlm Z ddl m Z m Z m Z mZmZmZmZmZddlmZmZGdddeZGdd d eeZGd d d eZGd d d eZGdddeZGdddeZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"Gddde"Z#Gddde"Z$Gd d!d!e"Z%Gd"d#d#eZ&Gd$d%d%eZ'Gd&d'd'e'Z(Gd(d)d)e'Z)Gd*d+d+e'Z*Gd,d-d-eZ+Gd.d/d/e+Z,Gd0d1d1e+Z-Gd2d3d3e+Z.Gd4d5d5e"e/Z0Gd6d7d7e+Z1dS)8)absolute_importdivisionprint_functionN)Sequence)YAML_COMMON_DICT_ERRORYAML_COMMON_LEADING_TAB_ERROR'YAML_COMMON_PARTIALLY_QUOTED_LINE_ERROR#YAML_COMMON_UNBALANCED_QUOTES_ERROR YAML_COMMON_UNQUOTED_COLON_ERROR#YAML_COMMON_UNQUOTED_VARIABLE_ERRORYAML_POSITION_DETAILSYAML_AND_SHORTHAND_ERROR) to_nativeto_textcs\eZdZdZdfdd Zedd Zejd d Zd d Zd dZ ddZ ddZ Z S) AnsibleErrora This is the base class for all errors raised from Ansible code, and can be instantiated with two optional parameters beyond the error message to control whether detailed information is displayed when the error occurred while parsing a data file of some kind. Usage: raise AnsibleError('some message here', obj=obj, show_content=True) Where "obj" is some subclass of ansible.parsing.yaml.objects.AnsibleBaseYAMLObject, which should be returned by the DataLoader() class. NTFcs6tt||||_||_t||_||_||_dSN) superr__init__ _show_content_suppress_extended_errorr_messageobjorig_exc)selfmessager show_contentsuppress_extended_errorr __class__;/usr/lib/python3.9/site-packages/ansible/errors/__init__.pyr7s  zAnsibleError.__init__cCsjddlm}|jg}t|j|rF|}|r`|js`|dt|n|j r`|dt|j d |S)Nr)AnsibleBaseYAMLObjectz %sz. %sr) Zansible.parsing.yaml.objectsr"r isinstancer_get_extended_errorrappendrrjoin)rr"rZextended_errorr r r!r@s    zAnsibleError.messagecCs ||_dSr)r)rvalr r r!rRscCs|jSrrrr r r!__str__VszAnsibleError.__str__cCs|jSrr(r)r r r!__repr__YszAnsibleError.__repr__cCsd}d}t|df}|}t|}||kr4|d}||}|sV|d8}||}q<|dkrj||d}Wdn1s~0Y||fS)z Returns the line in the file which corresponds to the reported error location, as well as the line preceding it (if the error did not occur on the first line), to provide context to the error. rrrN)open readlineslenstrip)r file_name line_number target_line prev_lineflinesZ file_lengthr r r!_get_error_lines_from_file\s  *z'AnsibleError._get_error_lines_from_filec Csd}zt|jj\}}}|t|||f7}|dvrx|jrx|||d\}}t|}t|}|rx|dd}td|r| d}d|d} t||d|df}|d| | f7}|t 7}n*d|dd} |d | | | f7}d |vr|t 7}d |vr:d |vr:d |vs.d|vr:|t 7}n>d|vrZd |vrZ|t7}nt|rt|dkrt||kr||dkr|ddkr|t7}n|d} t| dkrx| d} d} d} | dr| dsd} n| dr| dsd} t| dkrH| ddvrH| ddvrH|ddksX|ddkr\d} | rj|t7}| rx|t7}Wn:ttfy|d7}Ynty|d7}Yn0|S)a Given an object reporting the location of the exception in a file, return detailed information regarding it including: * the line which caused the error as well as the one preceding it * causes and suggested remedies for common syntax errors If this error was created with show_content=False, the reporting of content is suppressed, as the file contents may be sensitive (ie. vault data). r)zz r- z\w+(\s+)?=(\s+)?[\w/-]+=z^ herez+ The offending line appears to be: %s %s z- The offending line appears to be: %s %s %s  z{{z}}z"{{z'{{z:{{:F'T"r)r>r=z& (could not open file to display line)z6 (specified line no longer in file, maybe it changed?))rZ ansible_posr rr8rreplaceresearchrstripfindr rr rr0countr splitr1 startswithendswithrr IOError TypeError IndexError)rZ error_messageZsrc_filer3Z col_numberr4r5Z stripped_lineZerror_positionZ arrow_linepartsZmiddlematchZ unbalancedr r r!r$}s|      (                z AnsibleError._get_extended_error)rNTFN) __name__ __module__ __qualname____doc__rpropertyrsetterr*r+r8r$ __classcell__r r rr!r(s   !rc@seZdZdZdS)AnsibleAssertionErrorzInvalid assertionNrOrPrQrRr r r r!rVsrVc@seZdZdZdS)AnsibleOptionsErrorz" bad or incomplete options passed NrWr r r r!rXsrXc@seZdZdZdS)AnsibleParserErrorzJ something was detected early that is wrong about a playbook or data file NrWr r r r!rYsrYc@seZdZdZdS)AnsibleInternalErrorzV internal safeguards tripped, something happened in the code that should never happen NrWr r r r!rZsrZc@seZdZdZdS)AnsibleRuntimeErrorz0 ansible had a problem while running a playbook NrWr r r r!r[sr[c@seZdZdZdS)AnsibleModuleErrorz a module failed somehow NrWr r r r!r\sr\c@seZdZdZdS)AnsibleConnectionFailurez5 the transport / connection_plugin had a fatal error NrWr r r r!r]sr]c@seZdZdZdS)AnsibleAuthenticationFailurezinvalid username/password/keyNrWr r r r!r^sr^c@seZdZdZdS)AnsibleCallbackErrorz a callback failure NrWr r r r!r_sr_c@seZdZdZdS)AnsibleTemplateErrorzA template related errorNrWr r r r!r`sr`c@seZdZdZdS)AnsibleFilterError a templating failure NrWr r r r!rasrac@seZdZdZdS)AnsibleLookupErrorz a lookup failure NrWr r r r!rc srcc@seZdZdZdS)AnsibleUndefinedVariablerbNrWr r r r!rdsrdcs"eZdZdZdfdd ZZS) AnsibleFileNotFoundz a file missing failure rNTFc s||_||_|r|d7}|jr2|dt|j7}n|d7}|jrtt|jtrttd|j}|rh|d7}|d|7}|d7}tt|j|||||ddS)N zCould not find or access '%s'zCould not find filez zSearched in: %sz{ on the Ansible Controller. If you are using a module and expect the file to exist on the remote, see the remote_src optionrrrrr) r2pathsrr#rr&rrer) rrrrrrrhr2Zsearchedrr r!rs  zAnsibleFileNotFound.__init__)rNTFNNNrOrPrQrRrrUr r rr!resrecs"eZdZdZdfdd ZZS) AnsibleActionz/ Base Exception for Action plugin flow control rNTFcs4tt|j|||||d|dur*i|_n||_dS)Nrg)rrjrresultrrrrrrrkrr r!r8s zAnsibleAction.__init__)rNTFNNrir r rr!rj5srjcs"eZdZdZdfdd ZZS) AnsibleActionSkipz an action runtime skiprNTFcs2tt|j||||||d|jd|ddS)NrrrrrrkT)Zskippedmsg)rrmrrkupdaterlrr r!rEszAnsibleActionSkip.__init__)rNTFNNrir r rr!rmBsrmcs"eZdZdZdfdd ZZS) AnsibleActionFailz an action runtime failurerNTFcs8tt|j||||||d|jd|tddS)NrnT)Zfailedro exception)rrqrrkrp traceback format_excrlrr r!rMszAnsibleActionFail.__init__)rNTFNNrir r rr!rqKsrqc@seZdZdZdS)_AnsibleActionDonez an action runtime early exitNrWr r r r!ruSsrucs"eZdZdZdfdd ZZS)AnsiblePluginErrorz\ base class for Ansible plugin-related errors that do not need AnsibleError contextual data Ncstt||||_dSr)rrvrplugin_load_context)rrrwrr r!rZszAnsiblePluginError.__init__)NNrir r rr!rvXsrvc@seZdZdZdS)AnsiblePluginRemovedErrorz% a requested plugin has been removed NrWr r r r!rx_srxc@seZdZdZdS)AnsiblePluginCircularRedirectz*a cycle was detected in plugin redirectionNrWr r r r!rydsryc@seZdZdZdS)(AnsibleCollectionUnsupportedVersionErrorz8a collection is not supported by this version of AnsibleNrWr r r r!rzisrzc@seZdZdZdS)AnsibleFilterTypeErrorz2 a Jinja filter templating failure due to bad typeNrWr r r r!r{nsr{c@seZdZdZdS)AnsiblePluginNotFoundz- Indicates we did not find an Ansible plugin NrWr r r r!r|ssr|)2Z __future__rrrtypeZ __metaclass__rBrscollections.abcrZansible.errors.yaml_stringsrrrr r r r r Zansible.module_utils._textrr ExceptionrAssertionErrorrVrXrYrZr[r\r]r^r_r`rarcrdrerjrmrqrurvrxryrzrKr{r|r r r r!s@ ( /