%PDF- %PDF-
| Direktori : /lib/python3.9/site-packages/ansible/module_utils/common/__pycache__/ |
| Current File : //lib/python3.9/site-packages/ansible/module_utils/common/__pycache__/respawn.cpython-39.pyc |
a
�)g � @ sd d dl mZmZmZ eZd dlZd dlZd dlZd dl m
Z
mZ dd� Zdd� Z
dd � Zd
d� ZdS )� )�absolute_import�division�print_functionN)�to_bytes� to_nativec C s t tjd d�S )N�__main__Z
_respawned)�hasattr�sys�modules� r r �G/usr/lib/python3.9/site-packages/ansible/module_utils/common/respawn.py�
has_respawned s r
c C sZ t � rtd��t� }t�� \}}t�|t|�� t�|� tj | dg|d�}t
�|� dS )a�
Respawn the currently-running Ansible Python module under the specified Python interpreter.
Ansible modules that require libraries that are typically available only under well-known interpreters
(eg, ``yum``, ``apt``, ``dnf``) can use bespoke logic to determine the libraries they need are not
available, then call `respawn_module` to re-execute the current module under a different interpreter
and exit the current process when the new subprocess has completed. The respawned process inherits only
stdout/stderr from the current process.
Only a single respawn is allowed. ``respawn_module`` will fail on nested respawns. Modules are encouraged
to call `has_respawned()` to defensively guide behavior before calling ``respawn_module``, and to ensure
that the target interpreter exists, as ``respawn_module`` will not fail gracefully.
:arg interpreter_path: path to a Python interpreter to respawn the current module
z!module has already been respawnedz--)�stdinN)r
� Exception�_create_payload�os�pipe�writer �close�
subprocess�callr �exit)�interpreter_pathZpayloadZ
stdin_readZstdin_write�rcr r r �respawn_module s
r c C s` | D ]V}t j�|�sqz,t�|dd�|�g�}|dkr@|W S W q tyX Y qY q0 qdS )aG
Probes a supplied list of Python interpreters, returning the first one capable of
importing the named module. This is useful when attempting to locate a "system
Python" where OS-packaged utility modules are located.
:arg interpreter_paths: iterable of paths to Python interpreters. The paths will be probed
in order, and the first path that exists and can successfully import the named module will
be returned (or ``None`` if probing fails for all supplied paths).
:arg module_name: fully-qualified Python module name to probe for (eg, ``selinux``)
z-cz
import {0}r N)r �path�existsr r �formatr )Zinterpreter_pathsZmodule_namer r r r r �probe_interpreters_for_module/ s r c C sV ddl m} t| d�}|s"td��tjd j}tjd j}d}|j||t |�d�}|S )Nr )�basicZ
_ANSIBLE_ARGSzVunable to access ansible.module_utils.basic._ANSIBLE_ARGS (not launched by AnsiballZ?)r a�
import runpy
import sys
module_fqn = '{module_fqn}'
modlib_path = '{modlib_path}'
smuggled_args = b"""{smuggled_args}""".strip()
if __name__ == '__main__':
sys.path.insert(0, modlib_path)
from ansible.module_utils import basic
basic._ANSIBLE_ARGS = smuggled_args
runpy.run_module(module_fqn, init_globals=dict(_respawned=True), run_name='__main__', alter_sys=True)
)�
module_fqn�modlib_path�
smuggled_args)
Zansible.module_utilsr �getattrr r r
Z_module_fqnZ_modlib_pathr r )r r"