Your IP : 216.73.217.13


Current Path : /usr/lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ansible.cpython-38.pyc

U

�Adx!�
@s�UdZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZmZdd
lmZmZddlmZddlmZmZdd
lmZmZdddeegdged�ed�ed�gd�Z ee!d<ee �Ze	e"�Z#dZ$Gdd�dej%�Z&Gdd�de&�Z'Gdd�de&�Z(e)eeee*dd�dd �Z+e,d!�d"d#�Z-e,e,d$�d%d&�Z.e&e,d'�d(d)�Z/e,e&d*�d+d,�Z0e,e&d*�d-d.�Z1dS)/z9ansible enables running on first boot either ansible-pull�N)�deepcopy)�Logger�	getLogger)�dedent)�Optional)�Cloud)�Config)�
MetaSchema�get_meta_doc)�ALL_DISTROS�Distro)�PER_INSTANCE)�subp�which)�Version�get_cfg_by_pathZ
cc_ansibleZAnsiblezConfigure ansible for instance�ansiblea        This module provides ``ansible`` integration for
        augmenting cloud-init's configuration of the local
        node.


        This module installs ansible during boot and
        then uses ``ansible-pull`` to run the playbook
        repository at the remote URL.
        z�            ansible:
              install_method: distro
              pull:
                url: "https://github.com/holmanb/vmboot.git"
                playbook_name: ubuntu.yml
            z�            ansible:
              package_name: ansible-core
              install_method: pip
              pull:
                url: "https://github.com/holmanb/vmboot.git"
                playbook_name: ubuntu.yml
            )�id�name�titleZ	frequencyZdistrosZactivate_by_schema_keysZdescriptionZexamples�meta�ansible_configc@szeZdZed�dd�Zeed�dd�Zed�dd�Z	d	d
�Z
ed�dd
�Zdd�Z
ejdd��Zejed�dd��ZdS)�AnsiblePull)�distrocCs>dg|_ddg|_||_tj|_d|_|j�dd�|jd<dS)Nzansible-pullz	--version�HOMEz/root)�cmd_pull�cmd_versionr�os�environ�env�run_user�get)�selfr�r#�=/usr/lib/python3/dist-packages/cloudinit/config/cc_ansible.py�__init__Cs
zAnsiblePull.__init__��returncCsF|�|j�\}}|���d�}t�d|�}|rB|�d�}t�|�SdS)Nrz	([\d\.]+))	�do_asr�
splitlines�pop�re�search�grouprZfrom_str)r"�stdout�_Z
first_lineZmatches�versionr#r#r$�get_versionNs

zAnsiblePull.get_versioncGs|�|j|��\}}|S�N)r(r)r"�argsr.r/r#r#r$�pullWszAnsiblePull.pullcCs|��std��dS)Nz!command: ansible is not installed)�is_installed�
ValueError�r"r#r#r$�
check_deps[szAnsiblePull.check_deps)�commandcKs(|js|j|f|�S|jj||jf|�Sr2)r rrr(�r"r9�kwargsr#r#r$r(_szAnsiblePull.do_ascKst|fd|ji|��S)Nr)rrr:r#r#r$rdszAnsiblePull.subpcCsdSr2r#r7r#r#r$r5gszAnsiblePull.is_installed��pkg_namecCsdSr2r#�r"r=r#r#r$�installkszAnsiblePull.installN)�__name__�
__module__�__qualname__rr%rrr1�strr4r8�listr(r�abc�abstractmethodr5r?r#r#r#r$rBs	
rcsDeZdZeeed��fdd�Zed�dd�Zed�dd	�Z	�Z
S)
�AnsiblePullPip)r�usercsft��|�||_|�tjddg�\}}|�d�}|j�d�}|rXd�||g�|jd<n
||jd<dS)Nz-cz('import site; print(site.getuserbase())'z/bin/�PATH�:)	�superr%r r(�sys�
executablerr!�join)r"rrH�	user_baser/Zansible_pathZold_path��	__class__r#r$r%qs
�
zAnsiblePullPip.__init__r<cCsz|��svzddl}Wn$tk
r8|j�|jj�YnXtjdddg}|jrX|�	d�|�
|d��|�
||f��dS)	zishould cloud-init grow an interface for non-distro package
        managers? this seems reusable
        rN�-m�pipr?z--user�	--upgrade)rTrS)r5rS�ImportErrorr�install_packagesZpip_package_namerLrMr �appendr()r"r=rS�cmdr#r#r$r?�s
zAnsiblePullPip.installr&cCs |�tjdddg�\}}d|kS)NrRrSrDr)r(rLrM)r"r.r/r#r#r$r5�szAnsiblePullPip.is_installed)r@rArBrrrCr%r?�boolr5�
__classcell__r#r#rPr$rGpsrGc@s(eZdZed�dd�Zed�dd�ZdS)�AnsiblePullDistror<cCs|��s|j�|�dSr2)r5rrVr>r#r#r$r?�szAnsiblePullDistro.installr&cCsttd��S)Nr)rYrr7r#r#r$r5�szAnsiblePullDistro.is_installedN)r@rArBrCr?rYr5r#r#r#r$r[�sr[)r�cfg�cloud�logr3r'cCs�|�di�}|�d�}|�d�}|�d�}|�d�}	|�d�}
|�dd�}|r�t|�|j}|d	krpt||�}
nt|�}
|
�|�|
��|�d
d�}|r�||
jt<|	r�t	|	|
�|
r�t
|
t|
��|r�t||
�dS)Nrr �install_method�setup_controllerZgalaxyr4�package_name�rSr)
r!�validate_configrrGr[r?r8r�CFG_OVERRIDE�ansible_galaxy�run_ansible_pullr�ansible_controller)rr\r]r^r3Zansible_cfgZansible_userr_r`Z
galaxy_cfgZpull_cfgrarrrr#r#r$�handle�s0







rh�r\cCs�d}|D]"}t||�std|�d|����q|�d�r^dD]"}t||�s:td|�d|����q:|�d�}|r�t|�d�|�d�g�s�td	|����|d
}|dkr�td��dS)
N)r_razMissing required key 'z' from r4)zpull/urlzpull/playbook_namer`�repositories�run_ansiblezMissing required key from r_)rSrz Invalid install method {install})rr6r!�any)r\Z
required_keys�keyZcontroller_cfgr?r#r#r$rc�s&



��rc)r\r'cCsdd�|��D�S)zremove boolean false valuescSs&i|]\}}|dk	r|�dd�|�qS)Fr/�-)�replace��.0rm�valuer#r#r$�
<dictcomp>�s�
zfilter_args.<locals>.<dictcomp>)�itemsrir#r#r$�filter_args�s�ru)r4r\cCs�|�d�}|��}|s"t�d�n<|tddd�kr^|�d�r^td|j�d|j�d|j	�d	���|j
d
d�t|���D�|f��}|r�t
j�|��dS)N�
playbook_namezCannot parse ansible version��rZdiffzAnsible version �.z%doesn't support --diff flag, exiting.cSs2g|]*\}}|dk	r$d|�d|��nd|���qS)T�--�=r#rpr#r#r$�
<listcomp>�s�z$run_ansible_pull.<locals>.<listcomp>)r*r1�LOG�warningrr!r6�major�minorZpatchr4rurtrLr.�write)r4r\rv�vr.r#r#r$rf�s"

�
��rf)r\rcCs4|�dg�}|st�d|�|D]}|�|�q dS)N�actionszInvalid config: %s)r!r}r~r()r\rr�r9r#r#r$res
recCs�|�dg�D]}|�dd|d|dg�q|�dg�D]D}|�d�}|�d�}d	|fd
d�t|���D��}|j||d�q8dS)
NrjZgitZclone�source�pathrk�playbook_dirrvzansible-playbookcSs g|]\}}d|�d|���qS)rzr{r#rpr#r#r$r|sz&ansible_controller.<locals>.<listcomp>)�cwd)r!r(r*rurt)r\rZ
repositoryr3r�rvr9r#r#r$rgs�

��rg)2�__doc__rErr+rL�copyrZloggingrr�textwrapr�typingrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemar	r
Zcloudinit.distrosrrZcloudinit.settingsr
Zcloudinit.subprrZcloudinit.utilrrr�__annotations__r@r}rd�ABCrrGr[rCrDrh�dictrcrurfrergr#r#r#r$�<module>sd�
�	���*.%
�'