%PDF- %PDF-
Mini Shell

Mini Shell

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

a

�)g�q�@srddlmZmZmZeZdZdZdZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZddlmZmZmZddlmZdd	lmZdd
lmZz,ddlZddlZddl m!Z"e"�#�Z!dZ$Wn(e%�ydZZZ"Z!dZ$Yn0gd
�Z&dZ'dZ(dd�Z)Gdd�de*�Z+Gdd�de,�Z-Gdd�de-�Z.dd�Z/dd�Z0e1dk�rne0�dS)�)�absolute_import�division�print_functiona�
---
module: apt_repository
short_description: Add and remove APT repositories
description:
    - Add or remove an APT repositories in Ubuntu and Debian.
extends_documentation_fragment: action_common_attributes
attributes:
    check_mode:
        support: full
    diff_mode:
        support: full
    platform:
        platforms: debian
notes:
    - This module supports Debian Squeeze (version 6) as well as its successors and derivatives.
options:
    repo:
        description:
            - A source string for the repository.
        type: str
        required: true
    state:
        description:
            - A source string state.
        type: str
        choices: [ absent, present ]
        default: "present"
    mode:
        description:
            - The octal mode for newly created files in sources.list.d.
            - Default is what system uses (probably 0644).
        type: raw
        version_added: "1.6"
    update_cache:
        description:
            - Run the equivalent of C(apt-get update) when a change occurs.  Cache updates are run after making changes.
        type: bool
        default: "yes"
        aliases: [ update-cache ]
    update_cache_retries:
        description:
        - Amount of retries if the cache update fails. Also see I(update_cache_retry_max_delay).
        type: int
        default: 5
        version_added: '2.10'
    update_cache_retry_max_delay:
        description:
        - Use an exponential backoff delay for each retry (see I(update_cache_retries)) up to this max delay in seconds.
        type: int
        default: 12
        version_added: '2.10'
    validate_certs:
        description:
            - If C(false), SSL certificates for the target repo will not be validated. This should only be used
              on personally controlled sites using self-signed certificates.
        type: bool
        default: 'yes'
        version_added: '1.8'
    filename:
        description:
            - Sets the name of the source list file in sources.list.d.
              Defaults to a file name based on the repository source url.
              The .list extension will be automatically added.
        type: str
        version_added: '2.1'
    codename:
        description:
            - Override the distribution codename to use for PPA repositories.
              Should usually only be set when working with a PPA on
              a non-Ubuntu target (for example, Debian or Mint).
        type: str
        version_added: '2.3'
    install_python_apt:
        description:
            - Whether to automatically try to install the Python apt library or not, if it is not already installed.
              Without this library, the module does not work.
            - Runs C(apt-get install python-apt) for Python 2, and C(apt-get install python3-apt) for Python 3.
            - Only works with the system Python 2 or Python 3. If you are using a Python on the remote that is not
               the system Python, set I(install_python_apt=false) and ensure that the Python apt library
               for your Python version is installed some other way.
        type: bool
        default: true
author:
- Alexander Saltanov (@sashka)
version_added: "0.7"
requirements:
   - python-apt (python 2)
   - python3-apt (python 3)
   - apt-key or gpg
a!
- name: Add specified repository into sources list
  ansible.builtin.apt_repository:
    repo: deb http://archive.canonical.com/ubuntu hardy partner
    state: present

- name: Add specified repository into sources list using specified filename
  ansible.builtin.apt_repository:
    repo: deb http://dl.google.com/linux/chrome/deb/ stable main
    state: present
    filename: google-chrome

- name: Add source repository into sources list
  ansible.builtin.apt_repository:
    repo: deb-src http://archive.canonical.com/ubuntu hardy partner
    state: present

- name: Remove specified repository from sources list
  ansible.builtin.apt_repository:
    repo: deb http://archive.canonical.com/ubuntu hardy partner
    state: absent

- name: Add nginx stable repository from PPA and install its signing key on Ubuntu target
  ansible.builtin.apt_repository:
    repo: ppa:nginx/stable

- name: Add nginx stable repository from PPA and install its signing key on Debian target
  ansible.builtin.apt_repository:
    repo: 'ppa:nginx/stable'
    codename: trusty

- name: One way to avoid apt_key once it is removed from your distro
  block:
    - name: somerepo |no apt key
      ansible.builtin.get_url:
        url: https://download.example.com/linux/ubuntu/gpg
        dest: /etc/apt/trusted.gpg.d/somerepo.asc

    - name: somerepo | apt source
      ansible.builtin.apt_repository:
        repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/myrepo.asc] https://download.example.com/linux/ubuntu {{ ansible_distribution_release }} stable"
        state: present
�#N)�
AnsibleModule)�
has_respawned�probe_interpreters_for_module�respawn_module)�	to_native)�PY3)�	fetch_urlTF)z/etc/apt/keyringsz/etc/apt/trusted.gpg.dz/usr/share/keyringsi�)Zdebzdeb-srccCs�|js�|�d�}|r�|�|dg�\}}}|dkrH|jd||��fd�|�|d|ddg�\}}}|dkr�|jd||��fd�n|jd	|d�dS)
Nzapt-get�updaterz*Failed to auto-install %s. Error was: '%s'��msg�installz-yz-qz&%s must be installed to use check mode)�
check_mode�get_bin_path�run_command�	fail_json�strip)�module�apt_pkg_nameZapt_get_path�rcZsoZse�r�B/usr/lib/python3.9/site-packages/ansible/modules/apt_repository.py�install_python_apt�s
rc@seZdZdS)�
InvalidSourceN)�__name__�
__module__�__qualname__rrrrr�src@s�eZdZdd�Zdd�Zdd�Zdd�Zd$d
d�Zedd
��Z	edd��Z
dd�Zdd�Zdd�Z
dd�Zd%dd�Zdd�Zd&dd�Zd d!�Zd"d#�ZdS)'�SourcesListcCsb||_i|_t�|_|�d�|_tj�|j�r:|�	|j�t
�d|�d��D]}|�	|�qNdS)NzDir::Etc::sourcelistz	%s/*.list�Dir::Etc::sourceparts)
r�files�set�	new_repos�
_apt_cfg_file�default_file�os�path�isfile�load�globZiglob�_apt_cfg_dir)�selfr�filerrr�__init__�szSourcesList.__init__ccs@|j��D]0\}}|D]"\}}}}}|r|||||fVqq
dS)zeSimple iterator to go over all sources. Empty, non-source, and other not valid lines will be skipped.N)r"�items)r-r.�sources�n�valid�enabled�source�commentrrr�__iter__�szSourcesList.__iter__cCs,d|vr|Stj�tj�|�d�|��SdS)N�/r!)r'r(�abspath�joinr,)r-�filenamerrr�_expand_path�szSourcesList._expand_pathcsl�fdd�}dd�}t�dd|�}t�dd|�}dd	�|��D�}||d
�|d
<d|d�|dd
���S)Ncs0�jjd}|dur|Sd�t�dd|����S)Nr;�_z[^a-zA-Z0-9]� )r�paramsr:�re�sub�split)�sr;�r-rr�_cleanup_filename�sz8SourcesList._suggest_filename.<locals>._cleanup_filenamecSs d|vr|�dd�}|d}|S)N�@����)rB)rCrrr�_strip_username_password�sz?SourcesList._suggest_filename.<locals>._strip_username_passwordz
\[[^\]]+\]�z\w+://cSsg|]}|tvr|�qSr)�VALID_SOURCE_TYPES)�.0�partrrr�
<listcomp>��z1SourcesList._suggest_filename.<locals>.<listcomp>rz%s.listr>rG)r@rArBr:)r-�linerErI�partsrrDr�_suggest_filename�szSourcesList._suggest_filenameFc	Cs�d}d}d}d}|��}|�d�r2d}|dd�}|�d�}|dkrd||dd���}|d|�}|��}|r�|��}|dtvr�d}d�|�}|r�|r�|s�t|��||||fS)NFTrJrrGrr>)r�
startswith�findrBrKr:r)	r-rP�raise_if_invalid_or_disabledr3r4r5r6�i�chunksrrr�_parses*


zSourcesList._parsecCs4ztj�|�}Wnty.tj�|�}Yn0|S�zJ
        Wrapper for `apt_pkg` module for running with Python 2.5
        )�apt_pkg�configZ	find_file�AttributeError�ConfigZFindFile)Zfilespec�resultrrrr%#s
zSourcesList._apt_cfg_filecCs4ztj�|�}Wnty.tj�|�}Yn0|SrY)rZr[Zfind_dirr\r]ZFindDir)Zdirspecr^rrrr,.s
zSourcesList._apt_cfg_dirc
CsTg}t|d�}t|�D].\}}|�|�\}}}}	|�|||||	f�q||j|<dS)N�r)�open�	enumeraterX�appendr")
r-r.�group�fr2rPr3r4r5r6rrrr*9s
zSourcesList.loadcCst|j���D�]�\}}|�r�tj�|�\}}zt�|�WnHty�}z0tj�|�sp|j	�
d|t|�f�WYd}~n
d}~00ztj
d||d�\}}WnBttfy�}z&|j	j
d|t|�fd�WYd}~n
d}~00t�|d�}	|D]�\}
}}}
}g}|�s|�d�|�|
�|�r:|�d�|�|�|�d	�d
�|�}z|	�|�Wq�t�y�}z&|j	j
d|t|�fd�WYd}~q�d}~00q�|j	�||�||jv�r�|j	j�dt�}|j	�||d
�q|j|=tj�|�rt�|�qdS)Nz!Failed to create directory %s: %sz.%s-)�prefix�dirz5Unable to create temp file at "%s" for apt source: %sr�w�# � # �
rJzFailed to write to file %s: %s�modeF)�listr"r0r'r(rB�makedirs�OSError�isdirrrr
�tempfileZmkstemp�IOError�fdopenrbr:�writeZatomic_mover$r?�get�DEFAULT_SOURCES_PERMZset_mode_if_different�exists�remove)r-r;r1�d�fn�ex�fdZtmp_path�erdr2r3r4r5r6rWrPZ	this_moderrr�saveAsD.0





2zSourcesList.savecCs�i}|j��D]�\}}|rg}|D]\\}}}}}	g}
|sB|
�d�|
�|�|	rd|
�d�|
�|	�|
�d�|�d�|
��q"d�|�||<q|S)NrhrirjrJ)r"r0rbr:)r-Z
dumpstructr;r1�linesr2r3r4r5r6rWrrr�dumpks 




zSourcesList.dumpcCs|dur|S|S�Nr)r-�new�oldrrr�_choice}szSourcesList._choiceNc
CsR|j||dd�\}}}}	|||�||�|�||�|�||	�f|j||<dS)z�
        This function to be used with iterator, so we don't care of invalid sources.
        If source, enabled, or comment is None, original value from line ``n`` will be preserved.
        rGN)r"r�)
r-r.r2r4r5r6r3Zenabled_oldZ
source_oldZcomment_oldrrr�modify�szSourcesList.modifycCs�|j�d|||f�d}|D]*\}}}}}	||kr|j||dd�d}q|s�|dur^|j}n
|�|�}||jvr|g|j|<|j|}
|
�t|
�dd||f�|j�	|�dS)Nzading source file: %s | %s | %sFT)r4)
r�logr�r&r<r"rb�lenr$�add)r-Z
source_newZcomment_newr.�foundr;r2r4r5r6r"rrr�_add_valid_source�s



zSourcesList._add_valid_sourcerJcCs0|j|dd�d}|j|||p&|�|�d�dS)NT�rU�)r.)rXr�rR)r-rPr6r.r5rrr�
add_source�szSourcesList.add_sourcecCs4|D]*\}}}}}||kr|r|j|�|�qdSr�)r"�pop)r-r5r;r2r4�srcr6rrr�_remove_valid_source�sz SourcesList._remove_valid_sourcecCs |j|dd�d}|�|�dS)NTr�r�)rXr��r-rPr5rrr�
remove_source�szSourcesList.remove_source)F)NNN)rJN)rrrr/r7r<rRrX�staticmethodr%r,r*r}rr�r�r�r�r�r�rrrrr �s$




*

r csheZdZdZ�fdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
dd�Zedd��Z
�ZS)�UbuntuSourcesListz-https://launchpad.net/api/1.0/~%s/+archive/%scsj||_|jdptj|_tt|��|�|jjddd�|_|jjddd�|_	|jsf|j	sf|jj
dd�dS)N�codenamezapt-keyF)�requiredZgpgzDEither apt-key or gpg binary is required, but neither could be foundr)rr?�distror��superr�r/r�apt_key_bin�gpg_binr)r-r��	__class__rrr/�szUbuntuSourcesList.__init__NcCs
t|j�Sr�)r�r)r-�memorrr�__deepcopy__�szUbuntuSourcesList.__deepcopy__cCs`|j||f}tdd�}t|j||d�\}}|ddkrN|jjd|dd�t�t|����S)	Nzapplication/json)ZAccept)�headers�status��z.failed to fetch PPA information, error was: %srr)	�LP_API�dictrrr�json�loadsr
�read)r-Z
owner_name�ppa_nameZlp_apir�Zresponse�inforrr�
_get_ppa_info�s
zUbuntuSourcesList._get_ppa_infocCs`|�d�d}|�d�d}z|�d�d}WntyDd}Yn0d|||jf}|||fS)N�:rGr8r�ppaz1deb http://ppa.launchpad.net/%s/%s/ubuntu %s main)rB�
IndexErrorr�)r-r(r��	ppa_ownerr�rPrrr�_expand_ppa�s
zUbuntuSourcesList._expand_ppacCs@|jr2|jj|jd|gdd�\}}}t|�dk}n
|�|�}|S)NZexportT)�check_rcr)r�rrr��_gpg_key_exists)r-�key_fingerprintr�out�errr�rrr�_key_already_exists�s

z%UbuntuSourcesList._key_already_existsc	s�d}dg}tD]"�|��fdd�t���D��q|D]�}tj�|�r6z|j�|jd|g�\}}}WnJt	t
fy�}z.|�d|t|�f�WYd}~q6WYd}~n
d}~00||vr6d}q�q6|S)NFz/etc/apt/trusted.gpgcs$g|]}|�d�stj��|��qS)�.)rSr'r(r:)rL�x�Z	other_dirrrrN�rOz5UbuntuSourcesList._gpg_key_exists.<locals>.<listcomp>z--list-packetsz#Could check key against file %s: %sT)
�APT_KEY_DIRS�extendr'�listdirr(rvrrr�rqrn�debugr
)	r-r�r�ZkeyfilesZkey_filerr�r�r|rr�rr��s "z!UbuntuSourcesList._gpg_key_existsrJc
Cs|�d��r�|�|�\}}}||jvr*dS|�||�}|�|d��s�d}|jj�s�|jrt|jddddd|dg}	nftD]}
t	j
�|
�rxq�qx|j�d	d
�
t��d|
t	j
�|��dd
�||f}|jdddd|dg}	|jj|	ddd�\}}}
|�r�t|�dk�r|jjd||
|	d�zRt|d��}|�|�Wd�n1�sH0Y|j�d|d|f�WnBttf�y�}z$|jjd||
t|�d�WYd}~n
d}~00|�p�|�d||jf�}n"|j|dd�d}|�p�|�|�}|�|||�dS)N�ppa:Zsigning_key_fingerprintrJZadvz--recv-keysz--no-ttyz--keyserverzhkp://keyserver.ubuntu.com:80zNUnable to find any existing apt gpgp repo directories, tried the following: %sz, z%s/%s-%s-%s.gpgr>�-z--exportT)r��encodingrz"Unable to get required signing key)rr�stderr�command�wbz(Added repo key "%s" for apt to file "%s"z)Unable to add required signing key for%s )rrr��errorz%s_%sr�r�)rSr��
repos_urlsr�r�rrr�r�r'r(rvrr:�basename�replacer�rr�r`rsr�rnrqr
rRr�rXr�)r-rPr6r.r5r�r�r�Zkeyfiler�Zkeydirr�stdoutr�rdr|rrrr��s@

� *.zUbuntuSourcesList.add_sourcecCs:|�d�r|�|�d}n|j|dd�d}|�|�dS)Nr�rTr�r�)rSr�rXr�r�rrrr�+s
zUbuntuSourcesList.remove_sourcec
Cstg}|j��D]`}|D]V}|d}|d}|d}|r|s<q|�d�rb|�|�\}}}	|�|�q|�|�qq|S)NrGr��r�)r"�valuesrSr�rb)
r-Z
_repositoriesZparsed_reposZparsed_repor3r4Zsource_liner5r�r�rrrr�2s
zUbuntuSourcesList.repos_urls)N)rJN)rrrr�r/r�r�r�r�r�r�r��propertyr��
__classcell__rrr�rr��s

	

2r�cCs>t|����|���D]}tj�|�rt�|�q|��dS)z4Revert the sourcelist files to their previous state.N)r#�keys�
differencer'r(rvrwr})�sources_before�
sources_after�sourceslist_beforer;rrr�revert_sources_listGsr�cCs�tttddd�tddddgd�tdd�td	dd
gd�tdd
d�tddd�tdd�td	dd�td	dd�tdd�d�
dd�}|j}|jd}|jd}|jd}d}t�sZtr�dnd}t�r�|jd�|tj	�d�gd�}t
|d�}|r�t|�|j�r|jd|d�|d�rt
||�n|jd|d�t
|d�}|�rDt|�n|jd�|tj	�d�|�sl|jdd�tttj��r�t|�}n|jdd�t�|�}	|��}
z.|dk�r�|�|�n|dk�r�|�|�Wn:t�y
}z |jd t|�d�WYd}~n
d}~00|��}|
|k}
|
�r�|j�r�g}t|
����|���D]B}|�|
�|d!�|�|d!�|d"f||
v|d"f||vd#���qDni}|
�r�|j�s�z�|� �|�r�d!}|j�d$�}|j�d%�}t!�"d&d'�d(}t#|�D]~}zt$�%�}|�&�W�q�Wn2t$j'j(�y2}zt|�}WYd}~n
d}~00d)||}||k�rR||}t)�*|��q�t+|
||	�|jd*|�r||nd+d�WnFt,t-f�y�}z(t+|
||	�|jt|�d�WYd}~n
d}~00|j.|
|||d,�dS)-N�strT)�typer�ZpresentZabsent)r��default�choices�raw)r��boolzupdate-cache)r�r��aliases�int�)r�r��)
�repo�staterk�update_cache�update_cache_retries�update_cache_retry_max_delayr;rZvalidate_certsr�)Z
argument_specZsupports_check_moder�r�r�zpython3-aptz
python-aptz+{0} must be installed and visible from {1}.r)z/usr/bin/python3z/usr/bin/python2z/usr/bin/python�aptzX%s must be installed to use check mode. If run normally this module can auto-install it.rz4%s is not installed, and install_python_apt is Falsez/Please set argument 'repo' to a non-empty valuez1Module apt_repository is not supported on target.zInvalid repository string: %srJz	/dev/null)�beforeZafterZ
before_headerZafter_headerr�r�ri�g@�@r�zFailed to update apt cache: %szunknown reason)�changedr�r��diff)/rr�r?�HAVE_PYTHON_APTrrr�format�sys�
executablerr	rr�
isinstancer��aptsources_distroZDistributionr��copy�deepcopyrr�r�rr
Z_diffr#r��unionrbrtr}�randomZrandint�ranger�ZCacher
�cacheZFetchFailedException�time�sleepr�rnrqZ	exit_json)rr?r�r�r�ZsourceslistrZinterpretersZinterpreterr�r�rzr�r�r�r;r�r�r�Z	randomizeZretryr�r|Zdelayrrr�mainRs�




�
�



�






*
�
&r��__main__)2Z
__future__rrrr�Z
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNr�r+r�r'r@r�rpr�r�Zansible.module_utils.basicrZ#ansible.module_utils.common.respawnrrr	Zansible.module_utils._textr
Zansible.module_utils.sixrZansible.module_utils.urlsrr�rZZaptsources.distror�r�Z
get_distror��ImportErrorr�rurKr�	Exceptionr�objectr r�r�r�rrrrr�<module>	sR\,
e


Zerion Mini Shell 1.0