%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/executor/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/executor/__pycache__/module_common.cpython-39.opt-1.pyc

a

�)g�
@s�ddlmZmZmZeZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZmZmZddlmZddlmZmZddlmZddlmZddlmZdd	lmZ dd
l!m"Z"ddl#m$Z$m%Z%m&Z&ddl'm(Z(dd
l)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2Z3ddl4Z3e/�Z5e1dgd��Z6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>e
j?�@e
j?�AeB�dd�ZCdZDdZEdZFd ZGd!d"�ZHejI�r�eDZJneHeD�ZJe
j?�Ae
j?�Ae
j?�AeB���ZKe
�Ld#e
�MeK��ZNe
�Ld$�ZOe
�Ld%�ZPGd&d'�d'ejQ�ZRd(d)�ZSeT�d*fd+d,�ZUGd-d.�d.�ZVGd/d0�d0eV�ZWGd1d2�d2eV�ZXd3d4�ZYd5d6�ZZd7d8�Z[d9d:�Z\dDd;d<�Z]d=d>�Z^dEd@dA�Z_dFdBdC�Z`dS)G�)�absolute_import�division�print_functionN)�AST�Import�
ImportFrom)�BytesIO)�__version__�
__author__)�	constants)�AnsibleError)�!InterpreterDiscoveryRequiredError)�module_manifest)�AnsibleJSONEncoder)�to_bytes�to_text�	to_native)�module_utils_loader)�_get_collection_metadata�_nested_dict_get)�action_write_locks)�Display)�
namedtuple�ModuleUtilsProcessEntry)�
name_parts�is_ambiguousZhas_redirected_child�is_optionals"#<<INCLUDE_ANSIBLE_MODULE_COMMON>>s"<<ANSIBLE_VERSION>>"s)"<<INCLUDE_ANSIBLE_MODULE_COMPLEX_ARGS>>"s# POWERSHELL_COMMONs$<<INCLUDE_ANSIBLE_MODULE_JSON_ARGS>>s<<SELINUX_SPECIAL_FILESYSTEMS>>z# -*- coding: utf-8 -*-s# -*- coding: utf-8 -*-z..�module_utilsa�.%(shebang)s
%(coding)s
_ANSIBALLZ_WRAPPER = True # For test-module.py script to tell this is a ANSIBALLZ_WRAPPER
# This code is part of Ansible, but is an independent component.
# The code in this particular templatable string, and this templatable string
# only, is BSD licensed.  Modules which end up using this snippet, which is
# dynamically combined together by Ansible still belong to the author of the
# module, and they may assign their own license to the complete work.
#
# Copyright (c), James Cammarata, 2016
# Copyright (c), Toshio Kuratomi, 2016
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
#    * Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright notice,
#      this list of conditions and the following disclaimer in the documentation
#      and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
def _ansiballz_main():
    import os
    import os.path

    # Access to the working directory is required by Python when using pipelining, as well as for the coverage module.
    # Some platforms, such as macOS, may not allow querying the working directory when using become to drop privileges.
    try:
        os.getcwd()
    except OSError:
        try:
            os.chdir(os.path.expanduser('~'))
        except OSError:
            os.chdir('/')

%(rlimit)s

    import sys
    import __main__

    # For some distros and python versions we pick up this script in the temporary
    # directory.  This leads to problems when the ansible module masks a python
    # library that another import needs.  We have not figured out what about the
    # specific distros and python versions causes this to behave differently.
    #
    # Tested distros:
    # Fedora23 with python3.4  Works
    # Ubuntu15.10 with python2.7  Works
    # Ubuntu15.10 with python3.4  Fails without this
    # Ubuntu16.04.1 with python3.5  Fails without this
    # To test on another platform:
    # * use the copy module (since this shadows the stdlib copy module)
    # * Turn off pipelining
    # * Make sure that the destination file does not exist
    # * ansible ubuntu16-test -m copy -a 'src=/etc/motd dest=/var/tmp/m'
    # This will traceback in shutil.  Looking at the complete traceback will show
    # that shutil is importing copy which finds the ansible module instead of the
    # stdlib module
    scriptdir = None
    try:
        scriptdir = os.path.dirname(os.path.realpath(__main__.__file__))
    except (AttributeError, OSError):
        # Some platforms don't set __file__ when reading from stdin
        # OSX raises OSError if using abspath() in a directory we don't have
        # permission to read (realpath calls abspath)
        pass

    # Strip cwd from sys.path to avoid potential permissions issues
    excludes = set(('', '.', scriptdir))
    sys.path = [p for p in sys.path if p not in excludes]

    import base64
    import runpy
    import shutil
    import tempfile
    import zipfile

    if sys.version_info < (3,):
        PY3 = False
    else:
        PY3 = True

    ZIPDATA = """%(zipdata)s"""

    # Note: temp_path isn't needed once we switch to zipimport
    def invoke_module(modlib_path, temp_path, json_params):
        # When installed via setuptools (including python setup.py install),
        # ansible may be installed with an easy-install.pth file.  That file
        # may load the system-wide install of ansible rather than the one in
        # the module.  sitecustomize is the only way to override that setting.
        z = zipfile.ZipFile(modlib_path, mode='a')

        # py3: modlib_path will be text, py2: it's bytes.  Need bytes at the end
        sitecustomize = u'import sys\nsys.path.insert(0,"%%s")\n' %%  modlib_path
        sitecustomize = sitecustomize.encode('utf-8')
        # Use a ZipInfo to work around zipfile limitation on hosts with
        # clocks set to a pre-1980 year (for instance, Raspberry Pi)
        zinfo = zipfile.ZipInfo()
        zinfo.filename = 'sitecustomize.py'
        zinfo.date_time = ( %(year)i, %(month)i, %(day)i, %(hour)i, %(minute)i, %(second)i)
        z.writestr(zinfo, sitecustomize)
        z.close()

        # Put the zipped up module_utils we got from the controller first in the python path so that we
        # can monkeypatch the right basic
        sys.path.insert(0, modlib_path)

        # Monkeypatch the parameters into basic
        from ansible.module_utils import basic
        basic._ANSIBLE_ARGS = json_params
%(coverage)s
        # Run the module!  By importing it as '__main__', it thinks it is executing as a script
        runpy.run_module(mod_name='%(module_fqn)s', init_globals=dict(_module_fqn='%(module_fqn)s', _modlib_path=modlib_path),
                         run_name='__main__', alter_sys=True)

        # Ansible modules must exit themselves
        print('{"msg": "New-style module did not handle its own exit", "failed": true}')
        sys.exit(1)

    def debug(command, zipped_mod, json_params):
        # The code here normally doesn't run.  It's only used for debugging on the
        # remote machine.
        #
        # The subcommands in this function make it easier to debug ansiballz
        # modules.  Here's the basic steps:
        #
        # Run ansible with the environment variable: ANSIBLE_KEEP_REMOTE_FILES=1 and -vvv
        # to save the module file remotely::
        #   $ ANSIBLE_KEEP_REMOTE_FILES=1 ansible host1 -m ping -a 'data=october' -vvv
        #
        # Part of the verbose output will tell you where on the remote machine the
        # module was written to::
        #   [...]
        #   <host1> SSH: EXEC ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o
        #   PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o
        #   ControlPath=/home/badger/.ansible/cp/ansible-ssh-%%h-%%p-%%r -tt rhel7 '/bin/sh -c '"'"'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
        #   LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/badger/.ansible/tmp/ansible-tmp-1461173013.93-9076457629738/ping'"'"''
        #   [...]
        #
        # Login to the remote machine and run the module file via from the previous
        # step with the explode subcommand to extract the module payload into
        # source files::
        #   $ ssh host1
        #   $ /usr/bin/python /home/badger/.ansible/tmp/ansible-tmp-1461173013.93-9076457629738/ping explode
        #   Module expanded into:
        #   /home/badger/.ansible/tmp/ansible-tmp-1461173408.08-279692652635227/ansible
        #
        # You can now edit the source files to instrument the code or experiment with
        # different parameter values.  When you're ready to run the code you've modified
        # (instead of the code from the actual zipped module), use the execute subcommand like this::
        #   $ /usr/bin/python /home/badger/.ansible/tmp/ansible-tmp-1461173013.93-9076457629738/ping execute

        # Okay to use __file__ here because we're running from a kept file
        basedir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'debug_dir')
        args_path = os.path.join(basedir, 'args')

        if command == 'explode':
            # transform the ZIPDATA into an exploded directory of code and then
            # print the path to the code.  This is an easy way for people to look
            # at the code on the remote machine for debugging it in that
            # environment
            z = zipfile.ZipFile(zipped_mod)
            for filename in z.namelist():
                if filename.startswith('/'):
                    raise Exception('Something wrong with this module zip file: should not contain absolute paths')

                dest_filename = os.path.join(basedir, filename)
                if dest_filename.endswith(os.path.sep) and not os.path.exists(dest_filename):
                    os.makedirs(dest_filename)
                else:
                    directory = os.path.dirname(dest_filename)
                    if not os.path.exists(directory):
                        os.makedirs(directory)
                    f = open(dest_filename, 'wb')
                    f.write(z.read(filename))
                    f.close()

            # write the args file
            f = open(args_path, 'wb')
            f.write(json_params)
            f.close()

            print('Module expanded into:')
            print('%%s' %% basedir)
            exitcode = 0

        elif command == 'execute':
            # Execute the exploded code instead of executing the module from the
            # embedded ZIPDATA.  This allows people to easily run their modified
            # code on the remote machine to see how changes will affect it.

            # Set pythonpath to the debug dir
            sys.path.insert(0, basedir)

            # read in the args file which the user may have modified
            with open(args_path, 'rb') as f:
                json_params = f.read()

            # Monkeypatch the parameters into basic
            from ansible.module_utils import basic
            basic._ANSIBLE_ARGS = json_params

            # Run the module!  By importing it as '__main__', it thinks it is executing as a script
            runpy.run_module(mod_name='%(module_fqn)s', init_globals=None, run_name='__main__', alter_sys=True)

            # Ansible modules must exit themselves
            print('{"msg": "New-style module did not handle its own exit", "failed": true}')
            sys.exit(1)

        else:
            print('WARNING: Unknown debug command.  Doing nothing.')
            exitcode = 0

        return exitcode

    #
    # See comments in the debug() method for information on debugging
    #

    ANSIBALLZ_PARAMS = %(params)s
    if PY3:
        ANSIBALLZ_PARAMS = ANSIBALLZ_PARAMS.encode('utf-8')
    try:
        # There's a race condition with the controller removing the
        # remote_tmpdir and this module executing under async.  So we cannot
        # store this in remote_tmpdir (use system tempdir instead)
        # Only need to use [ansible_module]_payload_ in the temp_path until we move to zipimport
        # (this helps ansible-test produce coverage stats)
        temp_path = tempfile.mkdtemp(prefix='ansible_%(ansible_module)s_payload_')

        zipped_mod = os.path.join(temp_path, 'ansible_%(ansible_module)s_payload.zip')

        with open(zipped_mod, 'wb') as modlib:
            modlib.write(base64.b64decode(ZIPDATA))

        if len(sys.argv) == 2:
            exitcode = debug(sys.argv[1], zipped_mod, ANSIBALLZ_PARAMS)
        else:
            # Note: temp_path isn't needed once we switch to zipimport
            invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
    finally:
        try:
            shutil.rmtree(temp_path)
        except (NameError, OSError):
            # tempdir creation probably failed
            pass
    sys.exit(exitcode)

if __name__ == '__main__':
    _ansiballz_main()
a
        os.environ['COVERAGE_FILE'] = '%(coverage_output)s=python-%%s=coverage' %% '.'.join(str(v) for v in sys.version_info[:2])

        import atexit

        try:
            import coverage
        except ImportError:
            print('{"msg": "Could not import `coverage` module.", "failed": true}')
            sys.exit(1)

        cov = coverage.Coverage(config_file='%(coverage_config)s')

        def atexit_coverage():
            cov.stop()
            cov.save()

        atexit.register(atexit_coverage)

        cov.start()
a�
        try:
            if PY3:
                import importlib.util
                if importlib.util.find_spec('coverage') is None:
                    raise ImportError
            else:
                import imp
                imp.find_module('coverage')
        except ImportError:
            print('{"msg": "Could not find `coverage` module.", "failed": true}')
            sys.exit(1)
a�
    import resource

    existing_soft, existing_hard = resource.getrlimit(resource.RLIMIT_NOFILE)

    # adjust soft limit subject to existing hard limit
    requested_soft = min(existing_hard, %(rlimit_nofile)d)

    if requested_soft != existing_soft:
        try:
            resource.setrlimit(resource.RLIMIT_NOFILE, (requested_soft, existing_hard))
        except ValueError:
            # some platforms (eg macOS) lie about their hard limit
            pass
cCs>g}|��D]&}|��}|r|�d�r(q|�|�qd�|�S)N�#�
)�
splitlines�strip�
startswith�append�join)�source�buf�line�l�r)�B/usr/lib/python3.9/site-packages/ansible/executor/module_common.py�_strip_comments�sr+z*%s/(?P<path>ansible/modules/.*)\.(py|ps1)$zH/(?P<path>ansible_collections/[^/]+/[^/]+/plugins/modules/.*)\.(py|ps1)$s�(?:from +\.{2,} *module_utils.* +import |from +ansible_collections\.[^.]+\.[^.]+\.plugins\.module_utils.* +import |import +ansible_collections\.[^.]+\.[^.]+\.plugins\.module_utils.*|from +ansible\.module_utils.* +import |import +ansible\.module_utils\.)cs:eZdZd
�fdd�	Zdd�ZeZdd�Zdd	�Z�ZS)�ModuleDepFinderFcsXtt|�j|i|��||_t�|_t�|_||_||_t	|j
t|ji|_
|�|�dS)a�
        Walk the ast tree for the python module.
        :arg module_fqn: The fully qualified name to reach this module in dotted notation.
            example: ansible.module_utils.basic
        :arg is_pkg_init: Inform the finder it's looking at a package init (eg __init__.py) to allow
            relative import expansion to use the proper package level without having imported it locally first.

        Save submodule[.submoduleN][.identifier] into self.submodules
        when they are from ansible.module_utils or ansible_collections packages

        self.submodules will end up with tuples like:
          - ('ansible', 'module_utils', 'basic',)
          - ('ansible', 'module_utils', 'urls', 'fetch_url')
          - ('ansible', 'module_utils', 'database', 'postgres')
          - ('ansible', 'module_utils', 'database', 'postgres', 'quote')
          - ('ansible', 'module_utils', 'database', 'postgres', 'quote')
          - ('ansible_collections', 'my_ns', 'my_col', 'plugins', 'module_utils', 'foo')

        It's up to calling code to determine whether the final element of the
        tuple are module names or something else (function, class, or variable names)
        .. seealso:: :python3:class:`ast.NodeVisitor`
        N)�superr,�__init__�_tree�set�
submodules�optional_imports�
module_fqn�is_pkg_initr�visit_Importr�visit_ImportFrom�
_visit_map�visit)�selfr3�treer4�args�kwargs��	__class__r)r*r.�s�zModuleDepFinder.__init__cCsn|j}|j}t�|�D]R\}}t|t�r|D]:}t|ttf�rT||_||j	|�q,t|t
�r,||�q,qdS)z�Overridden ``generic_visit`` that makes some assumptions about our
        use case, and improves performance by calling visitors directly instead
        of calling ``visit`` to offload calling visitors.
        N)�
generic_visitr7�astZiter_fields�
isinstance�listrr�parentr>r)r9�noder?Z	visit_mapZfield�value�itemr)r)r*r?�s

zModuleDepFinder.generic_visitcCsf|jD]P}|j�d�s"|j�d�rt|j�d��}|j�|�|j|jkr|j	�|�q|�
|�dS)z�
        Handle import ansible.module_utils.MODLIB[.MODLIBn] [as asname]

        We save these as interesting submodules when the imported library is in ansible.module_utils
        or ansible.collections
        zansible.module_utils.�ansible_collections.�.N)�names�namer"�tuple�splitr1�addrCr/r2r?)r9rD�alias�py_modr)r)r*r5�s

�zModuleDepFinder.visit_ImportcCs>|jdkr||jr |jdp&dn|j}|jrtt|j�d��}|jr`d�|d|�|jf�}qzd�|d|��}q�|j}n|j}d}|jdjdkr�|j	�
d�nF|�d�r�t|�d��}n,|�d�r�|�d	�s�d
|vr�t|�d��}n|�r0|jD]8}|j	�
||jf�|j
|jkr�|j�
||jf�q�|�|�dS)a	
        Handle from ansible.module_utils.MODLIB import [.MODLIBn] [as asname]

        Also has to handle relative imports

        We save these as interesting submodules when the imported library is in ansible.module_utils
        or ansible.collections
        r�NrH�_six)rQzansible.module_utilsrGzplugins.module_utilsz.plugins.module_utils.)�levelr4r3rKrL�moduler$rIrJr1rMr"�endswithrCr/r2r?)r9rDZlevel_slice_offset�partsZnode_modulerOrNr)r)r*r6�s.



z ModuleDepFinder.visit_ImportFrom)F)	�__name__�
__module__�__qualname__r.r?r8r5r6�
__classcell__r)r)r=r*r,�s
%r,cCsVtj�|�s tdtj�|���t|d��}|��}Wd�n1sH0Y|S)Nz1imported module support code does not exist at %s�rb)�os�path�existsr�abspath�open�read)r\�fd�datar)r)r*�_slurpAs
&rcFc
Cstj�|���}d|}d|��}d}|dkr�|r>|d}q�tj�|�r�tjj||d�}	|�	|	���}|rt|dvr�d|}
|�
d	i�}|
|vr�td
||d��q�||
}q�td|d
d��n||vr�|�	|�
|����}|s�|}d�|�}|r�|dd�
|�}||fS)za
      Handles the different ways ansible allows overriding the shebang target for a module.
    zansible_%s_interpreterzINTERPRETER_%sN�pythonZansible_playbook_python�Z	variables)�auto�auto_legacyZauto_silentZauto_legacy_silentzdiscovered_interpreter_%sZ
ansible_factszinterpreter discovery needed)�interpreter_nameZdiscovery_modezinterpreter discovery requiredrgz#!{0}� )r[r\�basenamer!�upper�C�configZget_configuration_definition�get_config_value�template�getr
�formatr$)
�interpreter�	task_vars�templarr;�remote_is_localrhZinterpreter_configZinterpreter_config_keyZinterpreter_outZinterpreter_from_configZdiscovered_interpreter_configZfacts_from_task_vars�shebangr)r)r*�_get_shebangIs2


rwc@sTeZdZddd�Zedd��Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
dd�ZdS)�ModuleUtilLocatorBaseFcCsr||_||_||_d|_d|_||_d|_d|_d|_d|_	|rft
|�|��dkrf||dd�g|_n|g|_dS)NF�rP���)
Z
_is_ambiguous�_child_is_redirected�_is_optional�found�
redirected�
fq_name_parts�source_code�output_path�
is_package�_collection_name�len�!_get_module_utils_remainder_parts�candidate_names�r9rr�child_is_redirectedrr)r)r*r.�szModuleUtilLocatorBase.__init__cCsdd�|jD�S)NcSsg|]}d�|��qS)rH)r$)�.0�nr)r)r*�
<listcomp>��z@ModuleUtilLocatorBase.candidate_names_joined.<locals>.<listcomp>)r�)r9r)r)r*�candidate_names_joined�sz,ModuleUtilLocatorBase.candidate_names_joinedc
Cs�|�|�}|sdSzt|j�}WnVtyv}z>|jrDWYd}~dStd�d�|�|jt|����WYd}~n
d}~00t	|ddd�|�g�}|s�dS|�
d�}|du}|s�|�
d�}|�r|�
d�}|�
d	�}	|�
d
�}
d�d�|��}|
r�|d�|
�7}n|d7}t�||	|||j�d
|v�r�d|_
d�|�}d|_|d
}
|
�d��s�|
�d�}t|�dk�rvtd�||
���d�|d|dd�|dd���}
t�d�||
��|�||
�|_dSdS)NFzGerror processing module_util {0} loading redirected collection {1}: {2}rHZplugin_routingrZ	tombstoneZdeprecation�removal_date�removal_version�warning_textz module_util {0} has been removedz ({0})ZredirectT�ansible_collections�zinvalid redirect for {0}: {1}z4ansible_collections.{0}.{1}.plugins.module_utils.{2}rrP�z"redirecting module_util {0} to {1})r�rr��
ValueErrorr|rrqr$rrrp�display�
deprecatedr~r�r"rLr��	ExceptionZvvv�_generate_redirect_shim_sourcer�)r9rZmodule_utils_relative_partsZcollection_metadata�veZ
routing_entryZ	dep_or_tsZremovedr�r�r��msgZ
source_pkgZredirect_target_pkgZ
split_fqcnr)r)r*�_handle_redirect�sZ
�







�z&ModuleUtilLocatorBase._handle_redirectcCsgS)Nr)�r9rr)r)r*r��sz7ModuleUtilLocatorBase._get_module_utils_remainder_partscCsd�|�|��S)NrH)r$r�r�r)r)r*�_get_module_utils_remainder�sz1ModuleUtilLocatorBase._get_module_utils_remaindercCsdS)NFr)r�r)r)r*�_find_module�sz"ModuleUtilLocatorBase._find_moduleTcCs�|jD]6}|r|�|�rqV|�|�r*qV|s|�|�rqVq|jrRd|_d|_ndS|jrf|d}n|}d|_tjj	|�d|_
||_dS)NTry)r.�.py)r�r�r�r{r�r�r}r[r\r$r�r)r9�redirect_firstZcandidate_name_parts�
path_partsr)r)r*�_locate�s"


zModuleUtilLocatorBase._locatecCsd�||�S)Nz8
import sys
import {1} as mod

sys.modules['{0}'] = mod
)rq)r9Zfq_source_moduleZfq_target_moduler)r)r*r��s�z4ModuleUtilLocatorBase._generate_redirect_shim_sourceN)FFF)T)rVrWrXr.�propertyr�r�r�r�r�r�r�r)r)r)r*rx�s

;
rxcs.eZdZd	�fdd�	Zdd�Zdd�Z�ZS)
�LegacyModuleUtilLocatorFNcsftt|��|||�|dd�dkr2td�|���|ddkrJd}|g|_||_d|_|jdd	�dS)
Nrr���ansiblerz=this class can only locate from ansible.module_utils, got {0}�six)r�rr�zansible.builtinF)r�)	r-r�r.r�rqr��	_mu_pathsr�r�)r9rr�mu_pathsr�r=r)r*r.sz LegacyModuleUtilLocator.__init__cCs|dd�S)Nr�r)r�r)r)r*r�sz9LegacyModuleUtilLocator._get_module_utils_remainder_partscs�|�|��t��dkr|j}n�fdd�|jD�}tjj�d�|�|�|_}|dur�t	j
�|j�dtjj
vr�|j�d�|_|j}ndSt|�|_dS)NrPcs(g|] }tjj|g�dd��R��qS)Nrz)r[r\r$�r��p�Zrel_name_partsr)r*r�"r�z8LegacyModuleUtilLocator._find_module.<locals>.<listcomp>rH�/__init__.pyFT)r�r�r��	importlib�	machinery�
PathFinder�	find_specr$�_infor[r\�splitext�origin�SOURCE_SUFFIXESrTr�rcr�)r9r�paths�infor\r)r�r*r�s

�"
z$LegacyModuleUtilLocator._find_module)FNF)rVrWrXr.r�r�rYr)r)r=r*r�sr�cs.eZdZd�fdd�	Zdd�Zdd�Z�ZS)	�CollectionModuleUtilLocatorFcs|tt|��||||�|ddkr2td�|���n*t|�dkr\|dd�dkr\td�|���d	�|d
d��|_|��dS)Nrr�zMCollectionModuleUtilLocator can only locate from ansible_collections, got {0}�r��)ZpluginsrzoCollectionModuleUtilLocator can only locate below ansible_collections.(ns).(coll).plugins.module_utils, got {0}rHrP)	r-r�r.r�rqr�r$r�r�r�r=r)r*r.2s�z$CollectionModuleUtilLocator.__init__cCs�t|�dkrd|_d|_dSd�|dd��}tjj|dd��}d}zt�|ttj�|d���}Wnt	yvYn0|dur�d|_n,zt�|t|d��}Wnt	y�Yn0|dur�d	S||_dS)
Nr�ryTrHrr�z__init__.pyr�F)
r�r�r�r$r[r\�pkgutil�get_datar�ImportError)r9rZcollection_pkg_nameZresource_base_path�srcr)r)r*r�?s*z(CollectionModuleUtilLocator._find_modulecCs|dd�S)Nr�r)r�r)r)r*r�esz=CollectionModuleUtilLocator._get_module_utils_remainder_parts)FFF)rVrWrXr.r�r�rYr)r)r=r*r�1s
&r�c
s�dtt�dtt�ddfdd��dd�tjd	d
�D�}|�t�zt|ddtj	�}Wn:t
tfy�}ztd
||j
f��WYd}~n
d}~00t||���fdd��jD�}|�tdd	d	d	d��|�rh|��|�d�\}}	}
}|�vr�q�|dd�dk�rt||	||
d�}n2|ddk�r8t||	|
|d�}nt�d|g�q�|j�sp|�rZq�d�||j�}
t|
��|j�v�r~q�zt|jddtj	�}Wn>t
tf�y�}z td
|j|j
f��WYd}~n
d}~00td�|j�||j��|���fdd��jD��|j|jf�|j<g}|jdd�D]:}|�|�t |�}|�v�r*|�t|d	|j!|d���q*qʈD]@}�|d}|�"|�|d�t#|dd �}t�$d!|��qldS)"a�
    Using ModuleDepFinder, make sure we have all of the module_utils files that
    the module and its module_utils files needs. (no longer actually recursive)
    :arg name: Name of the python module we're examining
    :arg module_fqn: Fully qualified name of the python module we're scanning
    :arg module_data: string Python code of the module we're scanning
    :arg zf: An open :python:class:`zipfile.ZipFile` object that holds the Ansible module payload
        which we're assembling
    sUfrom pkgutil import extend_path
__path__=extend_path(__path__,__name__)
__version__="s"
__author__="s"
zansible/__init__.py)sHfrom pkgutil import extend_path
__path__=extend_path(__path__,__name__)
z ansible/module_utils/__init__.py))r�r�cSsg|]}tj�|�r|�qSr))r[r\�isdirr�r)r)r*r��r�z$recursive_finder.<locals>.<listcomp>F)�subdirsz	<unknown>�execzUnable to import %s due to %sNcs"g|]}t|dd|�jvd��qS)TF�r�rr2�r��m)�finderr)r*r��r�)r�rZbasicr�rr�r�)rr�r�r�)rr�rz=ModuleDepFinder improperly found a non-module_utils import %szFCould not find imported module support code for {0}.  Looked for ({1})rHc3s,|]$}|�vrt|dd|�jvd�VqdS)TFr�Nr�r��r�Zpy_module_cacher)r*�	<genexpr>�s
�z#recursive_finder.<locals>.<genexpr>rzrP�surrogate_or_strict��errorszIncluding module_utils file %s)%rr	r
rZ
_get_pathsr#�_MODULE_UTILS_PATH�compiler@Z
PyCF_ONLY_AST�SyntaxError�IndentationErrorrr�r,r1r�sort�popr�r�r��warningr}rqr�rr�r$r��extendr�rKr~�writestrrZvvvvv)rJr3�module_data�zfZmodule_utils_pathsr:�eZmodules_to_processZpy_module_namerr�rZmodule_infor�Zaccumulated_pkg_name�pkgZnormalized_nameZpy_module_file_nameZmu_filer)r�r*�recursive_finderis�������
(
���*�

r�cCsDttgd��ttdd��tdg�B�}|dd�}t|�d|��S)N)���	�
��
�� ��i)�	bytearrayr0�range�bool�	translate)�
b_module_dataZ	textchars�startr)r)r*�
_is_binary�s(r�cCsXd}t�|�}|st�|�}|rL|�d�}d|vr:td��d�|�d��}ntd��|S)ap
    Get the fully qualified name for an ansible module based on its pathname

    remote_module_fqn is the fully qualified name.  Like ansible.modules.system.ping
    Or ansible_collections.Namespace.Collection_name.plugins.modules.ping
    .. warning:: This function is for ansible modules only.  It won't work for other things
        (non-module plugins, etc)
    Nr\rHz7Module name (or path) was not a valid python identifier�/z1Unable to determine module's fully qualified name)�CORE_LIBRARY_PATH_RE�search�COLLECTION_PATH_RE�groupr�r$rL)�module_path�remote_module_fqn�matchr\r)r)r*�_get_ansible_module_fqn�s	


r�c	Cs�|�d�}d�|�d}|�||�|ddkr<d}t�}nd}t|���}t|t|��D]0}d�|d|��d	}||vr~qZ|�|d
�qZdS)zKAdd a module from ansible or from an ansible collection into the module ziprHr�r�rr�r�rPNr�r�)rLr$r��	frozensetZnamelistr�r�)	r�r�r�Zmodule_path_partsr�r�Zexisting_paths�idx�package_pathr)r)r*�_add_module_to_zip�s
r�c,Cs.d}}t|�rd}}n�t|vr8d}d}|�td�}n�t�|�rLd}d}n�t|vrjd}d}|�td�}n|t�d|tj�s�t�d	|tj�s�t�d
|tj�s�t�d|tj�s�t�d|tj�r�d}d}n"t|vr�d}d
}nd|vr�d}}d}|dvr�|||fSt	�}zt
|�}Wn&t�y4t�
d�d|}Yn0|dk�r^t|d�}zttj|tdd��}Wn6t�y�}ztdt|���WYd}~n
d}~00ztt|�}Wn(t�y�t�d|�tj}Yn0tj�tjd�}tj�|d||f�}d}tj� |��rPt�
d|�t!|d��}|�"�}Wd�n1�sB0Y�n�|t#j#v�rvt�
d|�t#j#|}nt�
d|�t#j#d}t�
d�|��4t�
d t$|��tj� |��s�t�
d!�t	�}tj%|d"|d#�}t&||||�t�
d$�t'|||�|�(�t)�*|�+��}tj� |��s\zt�,|�Wn$t-�yZtj� |��sV�Yn0t�
d%�t!|d&d'��}|�.|�Wd�n1�s�0Yt�
d(�t�/|d&|�t�
d)�Wd�n1�s�0Y|du�rNt�
d*�z8t!|d��}|�"�}Wd�n1�s$0YWnt0�yLtd+��Yn0t1|d,d-�}t2|�\} }!| du�rtd.} t3| |||!|d/�\}}"tj4j5d0|d1�}#t6|#t7��s�t7|�8|#��}#|#�r�t9t|#d2�}$nd3}$tj:�;d4�}%|%�rtj:d5}&|&�rt<t|%|&d6�}'nt=}'nd3}'t>j>�?�}(|�.t@tAt|||||tB|(jC|(jD|(jE|(jF|(jG|(jH|'|$d7���|�+�}n�|dk�r�d8}tI�J||||
|||	|
|||||�
}n�|d
k�r$t@tj|tdd��})t@t|)��}*|�tKt@ttL���}|�tM|*�}|�tNt@d9�tjO���}|�t|)�}d:t@|�;d;tjP�d,d-�}+|�d<|+�}|||fS)=z�
    Given the source of the module, convert it to a Jinja2 template to insert
    module code and return whether it's a new or old style module.
    �old�binary�newrds(from ansible.module_utils.basic import *Z
powershells,#Requires -Module Ansible.ModuleUtils.Legacys#Requires -Modules#Requires -Versions#AnsibleRequires -OSVersions#AnsibleRequires -Powershells#AnsibleRequires -CSharpUtilZjsonargss	WANT_JSON�non_native_want_jsonN)r�r�r�z)ANSIBALLZ: Could not determine module FQNzansible.modules.%s)ZANSIBLE_MODULE_ARGST)�clsZ
vault_to_textzDUnable to pass options to module, they must be JSON serializable: %szOBad module compression string specified: %s.  Using ZIP_STORED (no compression)Zansiballz_cachez%s-%sz"ANSIBALLZ: using cached module: %srZzANSIBALLZ: Using lock for %sz$ANSIBALLZ: Using generic lock for %szANSIBALLZ: Acquiring lockzANSIBALLZ: Lock acquired: %szANSIBALLZ: Creating module�w)�mode�compressionz&ANSIBALLZ: Writing module into payloadzANSIBALLZ: Writing modulez-part�wbzANSIBALLZ: Renaming modulezANSIBALLZ: Done creating modulez$ANSIBALLZ: Reading module after lockzvA different worker process failed to create module file. Look at traceback for that process for debugging information.r�r�z/usr/bin/python�ruZPYTHON_MODULE_RLIMIT_NOFILEre)�
rlimit_nofileryZ_ANSIBLE_COVERAGE_CONFIGZ_ANSIBLE_COVERAGE_OUTPUT)�coverage_config�coverage_output)�zipdataZansible_moduler3�paramsrvZcoding�year�month�day�hour�minute�second�coverage�rlimitz#!powershell�,ssyslog.Zansible_syslog_facilityssyslog.LOG_USER)Qr��REPLACER�replace�NEW_STYLE_PYTHON_MODULE_REr��REPLACER_WINDOWS�re�
IGNORECASE�REPLACER_JSONARGSrr�r�r��debug�dict�repr�json�dumpsr�	TypeErrorrr�getattr�zipfile�AttributeErrorr��
ZIP_STOREDr[r\r$rlZDEFAULT_LOCAL_TMPr]r_r`r�id�ZipFiler�r��close�base64Z	b64encode�getvalue�makedirs�OSError�write�rename�IOErrorr�_extract_interpreterrwrmrnrA�intro�ANSIBALLZ_RLIMIT_TEMPLATE�environrp�ANSIBALLZ_COVERAGE_TEMPLATE�!ANSIBALLZ_COVERAGE_CHECK_TEMPLATE�datetimeZutcnowr�ACTIVE_ANSIBALLZ_TEMPLATE�ENCODING_STRINGrrr	r
rr�ps_manifestZ_create_powershell_wrapper�REPLACER_VERSIONr	�REPLACER_COMPLEX�REPLACER_SELINUXZDEFAULT_SELINUX_SPECIAL_FSZDEFAULT_SYSLOG_FACILITY),�module_namer�r��module_argsrsrt�module_compression�
async_timeout�become�
become_method�become_user�become_password�become_flags�environmentruZmodule_substyle�module_stylerv�outputr�rZpython_repred_paramsr�Zcompression_methodZlookup_pathZcached_module_filenamerr��lockZ	zipoutputr��fZ
o_interpreterZo_argsrrrrrrr
ZnowZmodule_args_jsonZpython_repred_argsZfacilityr)r)r*�_find_module_utilss.

����



&,




*
*

,
�

�


�


�
rFcCsrd}g}|�dd�}|d�d�rj|d��}t�t|dd�dd��}d	d
�|D�}|d}|dd�}||fS)z�
    Used to extract shebang expression from binary module data and return a text
    string with the shebang, or None if no shebang is detected.
    N�
rPrs#!r�r�r�cSsg|]}t|dd��qS)r�r�)r)r��ar)r)r*r�#r�z(_extract_interpreter.<locals>.<listcomp>)rLr"r!�shlexr)r�rrr;�b_linesZ	b_shebangZ	cli_splitr)r)r*r+sr+r cCs(|durin|}|durin|}t|d��}|��}Wd�n1sH0Yt|||||||||||	|
|||
d�\}}}|dkr�||t|dd�fS|du�rt|�\}}|du�rt|||||
d�\}}|�dd	�}||kr�t|d
dd�|d<tj	�
|��d
��r|�d	t
�d�|�}|||fS)a
    Used to insert chunks of code into modules before transfer rather than
    doing regular python imports.  This allows for more efficient transfer in
    a non-bootstrapping scenario by not moving extra files over the wire and
    also takes care of embedding arguments in the transferred modules.

    This version is done in such a way that local imports can still be
    used in the module code, so IDEs don't have to be aware of what is going on.

    Example:

    from ansible.module_utils.basic import *

       ... will result in the insertion of basic.py into the module
       from the module_utils/ directory in the source tree.

    For powershell, this code effectively no-ops, as the exec wrapper requires access to a number of
    properties not available here.

    NrZ)r;r<r=r>r?r@rArur�Zpassthru)�	nonstringrrGrPr�)r�rKrrd)r_r`rFrr+rwrLrr[r\rjr"�insert�b_ENCODING_STRINGr$)r8r�r9rtrsr:r;r<r=r>r?r@rArurEr�rBrvrrr;Znew_interpreterrJr)r)r*�
modify_module*s,&�


rNc
Cs�|r|d}n|}|dur0d}tj||dd�|durNd}tj|d�g}n|�|g�}i}	i}
t|t�r�|D]}|
�|�qp|�|
�}
|
D]@}|�d�r�|�	d�d}||vr�|	�|
�d|�p�i�
��q�|	�|
�|i��
��|	�|�|	S)	Nrzz�Finding module_defaults for the action %s. The caller passed a list of redirected action names, which is deprecated. The task's resolved action should be provided as the first argument instead.z2.16)�versionz�Finding module_defaults for action %s. The caller has not passed the action_groups, so any that may include this action will be ignored.)r�zgroup/zgroup/%s)r�r�r�rprArB�updateror"rL�copy)
�actionr;�defaultsrtZredirected_namesZ
action_groupsZresolved_action_namer�Zgroup_namesZtmp_argsZmodule_defaults�defaultZ
group_namer)r)r*�get_action_args_with_defaultsds6
��



rU)F)
Nr rFNNNNNF)NN)aZ
__future__rrr�typeZ
__metaclass__r@r$r1rr[rIrrr�rrr�iorZansible.releaser	r
r�rrlZansible.errorsrZ&ansible.executor.interpreter_discoveryr
Zansible.executor.powershellrr4Z ansible.module_utils.common.jsonrZ+ansible.module_utils.common.text.convertersrrrZansible.plugins.loaderrZ2ansible.utils.collection_loader._collection_finderrrZansible.executorrZansible.utils.displayr�collectionsr�importlib.utilr��importlib.machineryr�rrr5r6rrr7r3rMr\r$�dirname�__file__r�ZANSIBALLZ_TEMPLATEr/r0r-r+ZDEFAULT_KEEP_REMOTE_FILESr2Z
site_packagesr��escaper�r�rZNodeVisitorr,rcrKrwrxr�r�r�r�r�r�rFr+rNrUr)r)r)r*�<module>s�

�9*8o!�
y�
:

Zerion Mini Shell 1.0