o nnh9@sddlmZddlZddlZddlmZddlmZmZm Z m Z m Z m Z m Z mZddlmZmZGdddeZGdd d eZGd d d eZGd d d eeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZ Gd d!d!e Z!Gd"d#d#e 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(Gd0d1d1eZ)Gd2d3d3e)Z*Gd4d5d5e)Z+Gd6d7d7e)Z,Gd8d9d9e e-Z.Gd:d;d;e)Z/dS)<) annotationsN)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__B/usr/local/lib/python3.10/dist-packages/ansible/errors/__init__.pyr5s   zAnsibleError.__init__cCshddlm}|jg}|jr|dt|jt|j|r/|}|r/|j s/|dt|d |S)Nr)AnsibleBaseYAMLObjectz. %sz %sr) ansible.parsing.yaml.objectsr rrappendr isinstancer_get_extended_errorrjoin)rr rextended_errorrrrr>s     zAnsibleError.messagecCs ||_dSr)r)rvalrrrrTs cC|jSrrrrrr__str__XzAnsibleError.__str__cCr(rr)r*rrr__repr__[r,zAnsibleError.__repr__cCsd}d}t|dC}|}t|}||kr|d}||}|s.|d8}||}|r"|dkrB||d}Wd||fSWd||fS1sOwY||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_lineflines file_lengthrrr_get_error_lines_from_file^s*   z'AnsibleError._get_error_lines_from_filec Csd}z>|jj\}}}|t|||f7}|dvr3|jr6|||d\}}t|}t|}|r9|dd}td|re| d}d|d} t||d|df}|d| | f7}|t 7}nd|dd} |d | | | f7}d |vr|t 7}d |vrd |vrd |vsd|vr|t 7}W|Sd|vrd |vr|t7}W|St|rt|dkrt||kr||dkr|ddkr|t7}W|S|d} t| dkr<| d} d} d} | dr| dsd} n | dr| dsd} t| dkr| ddvr| ddvr|ddks |ddkr"d} | r)|t7}| r?|t7}W|SW|SW|SW|SW|SW|SttfyR|d7}Y|Sty`|d7}Y|Sw)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)rAr@z& (could not open file to display line)z6 (specified line no longer in file, maybe it changed?))r ansible_posr rr;r replaceresearchrstripfindr rr rr2countrsplitr3 startswithendswithrrIOError TypeError IndexError)r error_messagesrc_filer5 col_numberr6r7 stripped_lineerror_position arrow_linepartsmiddlematch unbalancedrrrr$s       , )    "   EEA  z AnsibleError._get_extended_error)rNTFN) __name__ __module__ __qualname____doc__rpropertyrsetterr+r-r;r$ __classcell__rrrrr&s  !rc@eZdZdZdS)AnsiblePromptInterruptzUser interruptNr[r\r]r^rrrrrcrcc@rb)AnsiblePromptNoninteractivezUnable to get user inputNrdrrrrrfrerfc@rb)AnsibleAssertionErrorzInvalid assertionNrdrrrrrgrgc@rb)AnsibleOptionsErrorz" bad or incomplete options passed Nrdrrrrrirhric@rb)AnsibleParserErrorzJ something was detected early that is wrong about a playbook or data file Nrdrrrrrjrhrjc@rb)AnsibleInternalErrorzV internal safeguards tripped, something happened in the code that should never happen Nrdrrrrrkrhrkc@rb)AnsibleRuntimeErrorz0 ansible had a problem while running a playbook Nrdrrrrrlrhrlc@rb)AnsibleModuleErrorz a module failed somehow Nrdrrrrrmrhrmc@rb)AnsibleConnectionFailurez5 the transport / connection_plugin had a fatal error Nrdrrrrrnrhrnc@rb)AnsibleAuthenticationFailurezinvalid username/password/keyNrdrrrrrorhroc@rb)AnsibleCallbackErrorz a callback failure Nrdrrrrrprhrpc@rb)AnsibleTemplateErrorzA template related errorNrdrrrrrq rhrqc@rb)AnsibleFilterError a templating failure Nrdrrrrrrrhrrc@rb)AnsibleLookupErrorz a lookup failure Nrdrrrrrtrhrtc@rb)AnsibleUndefinedVariablersNrdrrrrrurhruc"eZdZdZdfdd ZZS) AnsibleFileNotFoundz a file missing failure rNTFc s||_||_|r |d7}|jr|dt|j7}n|d7}|jr:t|jtr:td|j}|r4|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) r4pathsr r#rr%rrwr) rrrrrrrzr4searchedrrrr$s   zAnsibleFileNotFound.__init__)rNTFNNNr[r\r]r^rrarrrrrw!rwcrv) AnsibleActionz/ Base Exception for Action plugin flow control rNTFcs6tt|j|||||d|duri|_dS||_dS)Nry)rr~rresultrrrrrrrrrrrBs   zAnsibleAction.__init__rNTFNNr|rrrrr~?r}r~crv) AnsibleActionSkipz an action runtime skiprNTFcs2tt|j||||||d|jd|ddS)NrrrrrrT)skippedmsg)rrrrupdaterrrrrOszAnsibleActionSkip.__init__rr|rrrrrLr}rcrv) AnsibleActionFailz an action runtime failurerNTFcs8tt|j||||||d|jd|tddS)NrT)failedr exception)rrrrr traceback format_excrrrrrWszAnsibleActionFail.__init__rr|rrrrrUrc@rb)_AnsibleActionDonez an action runtime early exitNrdrrrrr]rhrcs"eZdZdZdfdd ZZS)AnsiblePluginErrorz\ base class for Ansible plugin-related errors that do not need AnsibleError contextual data Ncstt||||_dSr)rrrplugin_load_context)rrrrrrrds zAnsiblePluginError.__init__)NNr|rrrrrbrrc@rb)AnsiblePluginRemovedErrorz% a requested plugin has been removed Nrdrrrrrirhrc@rb)AnsiblePluginCircularRedirectz*a cycle was detected in plugin redirectionNrdrrrrrnrhrc@rb)(AnsibleCollectionUnsupportedVersionErrorz8a collection is not supported by this version of AnsibleNrdrrrrrsrhrc@rb)AnsibleFilterTypeErrorz2 a Jinja filter templating failure due to bad typeNrdrrrrrxrhrc@rb)AnsiblePluginNotFoundz- Indicates we did not find an Ansible plugin Nrdrrrrr}rhr)0 __future__rrFrcollections.abcransible.errors.yaml_stringsrrrrrr r r +ansible.module_utils.common.text.convertersr r ExceptionrrcrfAssertionErrorrgrirjrkrlrmrnrorprqrrrtrurwr~rrrrrrrrOrrrrrrsD  ( 3