HEX
Server: nginx/1.18.0
System: Linux oas2 6.8.0-1039-oracle #40~22.04.1-Ubuntu SMP Wed Oct 29 05:11:00 UTC 2025 aarch64
User: root (0)
PHP: 8.1.2-1ubuntu2.23
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ansible.cpython-310.pyc
o

쑛h�)�
@s�UdZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZddlm
Z
mZddlmZddlmZddlmZdd	lmZmZdd
lmZddlmZdeegd
gd�Zeed<e�e�Z dZ!Gdd�dej"�Z#Gdd�de#�Z$Gdd�de#�Z%de&dedede'ddf
dd�Z(de)fdd�Z*de)de)fd d!�Z+d"e#de)fd#d$�Z,de)d
e#fd%d&�Z-de)d
e#fd'd(�Z.dS))z9ansible enables running on first boot either ansible-pull�N)�deepcopy)�List�Optional)�	lifecycle�subp)�Cloud)�Config)�
MetaSchema)�ALL_DISTROS�Distro)�PER_INSTANCE)�get_cfg_by_path�
cc_ansible�ansible)�id�	frequency�distros�activate_by_schema_keys�meta�ansible_configc@s|eZdZdefdd�Zdeejfdd�Zde	fdd�Z
d	d
�Zdefdd
�Z
dd�Zejdd��Zejde	fdd��ZdS)�AnsiblePull�distrocCs<dg|_ddg|_||_i|_d|_tj�dd�|jd<dS)Nzansible-pullz	--version�HOMEz/root)�cmd_pull�cmd_versionr�env�run_user�os�environ�get)�selfr�r!�=/usr/lib/python3/dist-packages/cloudinit/config/cc_ansible.py�__init__ s
zAnsiblePull.__init__�returncCsH|�|j�\}}|���d�}t�d|�}|r"|�d�}tj�	|�SdS)Nrz	([\d\.]+))
�do_asr�
splitlines�pop�re�search�groupr�Version�from_str)r �stdout�_�
first_line�matches�versionr!r!r"�get_version+s
zAnsiblePull.get_versioncGs|�g|j�|��\}}|S�N)r%r)r �argsr-r.r!r!r"�pull4szAnsiblePull.pullcCs|��std��dS)Nz!command: ansible is not installed)�is_installed�
ValueError�r r!r!r"�
check_deps8s�zAnsiblePull.check_deps�commandcKs0|js|j|fi|��S|jj||jfi|��Sr3)rrrr%�r r:�kwargsr!r!r"r%<szAnsiblePull.do_ascKstj|fd|ji|��S)N�
update_env)rrr;r!r!r"rAszAnsiblePull.subpcC�dSr3r!r8r!r!r"r6D�zAnsiblePull.is_installed�pkg_namecCr>r3r!�r r@r!r!r"�installHr?zAnsiblePull.installN)�__name__�
__module__�__qualname__rr#rrr+r2�strr5r9�listr%r�abc�abstractmethodr6rBr!r!r!r"rs	
rcsdeZdZdedeef�fdd�Zdd�Zdd�Zd	efd
d�Z	de
fd
d�Zdefdd�Z
�ZS)�AnsiblePullPipr�usercst��|�||_|��dSr3)�superr#r�add_pip_install_site_to_path�r rrK��	__class__r!r"r#NszAnsiblePullPip.__init__cCs`|jr.|�tjddg�\}}|�d�}|j�d�}|r'd�||g�|jd<dS||jd<dSdS)Nz-cz&import site; print(site.getuserbase())z/bin/�PATH�:)rr%�sys�
executablerr�join)r �	user_baser.�ansible_path�old_pathr!r!r"rMSs��
�z+AnsiblePullPip.add_pip_install_site_to_pathcCs6zddl}WdSty|j�|jjg�YdSw)Nr)�pip�ImportErrorr�install_packages�pip_package_name)r rYr!r!r"�bootstrap_pip_if_requiredds
�z(AnsiblePullPip.bootstrap_pip_if_requiredr@cCs�|��|��sFtjdddg}tj�tj�t�	d�d��r"|�
d�|jr*|�
d�|�|�t
�d|�|�g|�|��t
�d	|�d
Sd
S)zishould cloud-init grow an interface for non-distro package
        managers? this seems reusable
        �-mrYrB�stdlibzEXTERNALLY-MANAGEDz--break-system-packages�--userzInstalling the %s packagezInstalled the %s packageN)r]r6rSrTr�path�existsrU�	sysconfig�get_path�appendr�_AnsiblePullPip__upgrade_pip�LOG�infor%)r r@�cmdr!r!r"rBjs(�
��


�zAnsiblePullPip.installric
Csht�d�z
|�g|�d�d��Wntjy,}z
t�d|�WYd}~dSd}~wwt�d�dS)zOTry to upgrade pip then not raise an exception
        if the pip upgrade failsz
Upgrading pipz	--upgraderYzZFailed at upgrading pip. This is usually not criticalso the script will skip this step.
%sNzUpgraded pip)rgrhr%r�ProcessExecutionError�warning)r ri�er!r!r"�
__upgrade_pip�s
���	zAnsiblePullPip.__upgrade_pipr$cCs4tjdddg}|jr|�d�|�|�\}}d|vS)Nr^rYrGr`r)rSrTrrer%)r rir-r.r!r!r"r6�s

zAnsiblePullPip.is_installed)rCrDrErrrFr#rMr]rBrGrf�boolr6�
__classcell__r!r!rOr"rJMsrJcsFeZdZdedeef�fdd�Zdefdd�Zdefd	d
�Z	�Z
S)�AnsiblePullDistrorrKcst��|�||_dSr3)rLr#rrNrOr!r"r#�s
zAnsiblePullDistro.__init__r@cCs|��s
|j�|g�dSdSr3)r6rr[rAr!r!r"rB�s�zAnsiblePullDistro.installr$cCstt�d��S)Nr)rnr�whichr8r!r!r"r6�szAnsiblePullDistro.is_installed)rCrDrErrrFr#rBrnr6ror!r!rOr"rp�srp�name�cfg�cloudr4r$cCs�|�di�}|�d�}|�d�}|�d�}|�d�}|�d�}	|�dd�}
|ryt|�|j}|d	kr8t||�}nt||�}|�|
�|��|�d
d�}
|
rS|
|jt<|rZt	||�|	rpt
|	t�rd|	g}	|	D]	}t|t
|��qf|r{t||�dSdSdS)Nrr�install_method�setup_controller�galaxyr5�package_name�rYr)r�validate_configrrJrprBr9r�CFG_OVERRIDE�ansible_galaxy�
isinstance�dict�run_ansible_pullr�ansible_controller)rrrsrtr4�ansible_cfg�ansible_userrurv�
galaxy_cfg�pull_cfgrxrrrr!r!r"�handle�s:









�r�c	Cs6d}|D]}t||�std|�d|����q|�d�}|rst|t�r&|g}nt|t�s2td|����|D]>}t|t�sBtd|����t|d�sNtd|����t|d	�}t|d
�}t||g�setd|����t||g�rrtd|����q4|�d
�}|r�t|�d�|�d�g�s�td|����|d}|dvr�td��dS)N)rurxzMissing required key 'z' from r5zLInvalid value ansible.pull. Expected either dict of list of dicts but found z7Invalid value of ansible.pull. Expected dict but found �urlz Missing required key 'url' from �
playbook_name�playbook_namesz+Missing required key 'playbook_names' from zzKey 'ansible.pull.playbook_name' and 'ansible.pull.playbook_names' are mutually exclusive. Please use 'playbook_names' in rv�repositories�run_ansiblezMissing required key from ru)rYrz Invalid install method {install})r
r7rr}r~rG�any�all)	rs�
required_keys�keyr��p_cfg�has_playbook�
has_playbooks�controller_cfgrBr!r!r"rz�sb
�


��
��


����
���rzcCsdd�|��D�S)zremove boolean false valuescSs&i|]\}}|dur|�dd�|�qS)Fr.�-)�replace��.0r��valuer!r!r"�
<dictcomp>
s
�zfilter_args.<locals>.<dictcomp>)�items)rsr!r!r"�filter_argss�r�r5cCs|�dd�}|�dd�}|r|g}|��}|st�d�n|t�ddd�kr<|�d�r<td|j�d	|j	�d	|j
�d
���dd�t|���D�}|ri|t�dd
d�kri|j
g|�|�R�}|rgtj�|��dSdS|D]}|j
g|�|�R�}|r�tj�|��qkdS)Nr�r�zCannot parse ansible version��r�diffzAnsible version �.z%doesn't support --diff flag, exiting.cSs2g|]\}}|durd|�d|��nd|���qS)T�--�=r!r�r!r!r"�
<listcomp>#s ��z$run_ansible_pull.<locals>.<listcomp>�)r'r2rgrkrr+rr7�major�minor�patchr�r�r5rSr-�write)r5rsr�r��v�	pull_argsr-�playbookr!r!r"rs4
�
����rcCs4|�dg�}|st�d|�|D]}|�|�qdS)N�actionszInvalid config: %s)rrgrkr%)rsrr�r:r!r!r"r|5s�r|cCs�|�dg�D]}|�dd|d|dg�q|�dg�D]"}|�d�}|�d�}d	|gd
d�t|���D��}|j||d�qdS)
Nr��git�clone�sourcerar��playbook_dirr�zansible-playbookcSs g|]\}}d|�d|���qS)r�r�r!r�r!r!r"r�Is z&ansible_controller.<locals>.<listcomp>)�cwd)rr%r'r�r�)rsr�
repositoryr4r�r�r:r!r!r"r�>s�

���r�)/�__doc__rH�loggingrr(rSrc�copyr�typingrr�	cloudinitrr�cloudinit.cloudr�cloudinit.configr�cloudinit.config.schemar	�cloudinit.distrosr
r�cloudinit.settingsr�cloudinit.utilr
r�__annotations__�	getLoggerrCrgr{�ABCrrJrprFrGr�r~rzr�rr|r�r!r!r!r"�<module>s@�
.T
(5	!