
    Vhbz                       d dl mZ dZdZdZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
lmZ d dlmZ 	 d dlZd dlZd dlm Z!  e!jD                         Z dZ#g dZ%dZ&d Z' G d de(      Z) G d de*      Z+ G d de+      Z,d Z-d Z.e/dk(  r e.        yy# e$$ r dxZxZxZ!Z dZ#Y Ow xY w)    )annotationsa7  
---
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.
seealso:
  - module: ansible.builtin.deb822_repository
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 C(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 O(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 O(update_cache_retries)) up to this max delay in seconds.
        type: int
        default: 12
        version_added: '2.10'
    validate_certs:
        description:
            - If V(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 C(sources.list.d).
              Defaults to a file name based on the repository source url.
              The C(.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 O(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/keyrings/somerepo.asc

    - name: somerepo | apt source
      ansible.builtin.apt_repository:
        repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/myrepo.asc] https://download.example.com/linux/ubuntu {{ ansible_distribution_release }} stable"
        state: present
aN  
repo:
  description: A source string for the repository
  returned: always
  type: str
  sample: "deb https://artifacts.elastic.co/packages/6.x/apt stable main"

sources_added:
  description: List of sources added
  returned: success, sources were added
  type: list
  sample: ["/etc/apt/sources.list.d/artifacts_elastic_co_packages_6_x_apt.list"]
  version_added: "2.15"

sources_removed:
  description: List of sources removed
  returned: success, sources were removed
  type: list
  sample: ["/etc/apt/sources.list.d/artifacts_elastic_co_packages_6_x_apt.list"]
  version_added: "2.15"
N)AnsibleModule)S_IRWU_RG_RO)has_respawnedprobe_interpreters_for_modulerespawn_module)	to_native)	fetch_url)get_best_parsable_localeTF)z/etc/apt/keyringsz/etc/apt/trusted.gpg.dz/usr/share/keyrings)debzdeb-srcc                   | j                   s| j                  d      }|r| j                  |dg      \  }}}|dk7  r'| j                  d|d|j	                         d       | j                  |d|d	d
g      \  }}}|dk7  r(| j                  d|d|j	                         d       y y y | j                  d|z         y )Nzapt-getupdater   zFailed to auto-install z. Error was: ''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_nameapt_get_pathrcsoses         N/home/dcms/DCMS/lib/python3.12/site-packages/ansible/modules/apt_repository.pyinstall_python_aptr      s    **95++\8,DEJBBQw  Uaceckckcm%n o++\9lTXZ^,_`JBBQw  Uaceckckcm%n o   	ETU    c                      e Zd Zy)InvalidSourceN)__name__
__module____qualname__ r    r   r"   r"      s    r    r"   c                      e Zd Zd Zd Zd Zd ZddZed        Z	ed        Z
d Zd	 Zd
 Zd ZddZd ZddZd Zd Zy)SourcesListc                   || _         i | _        i | _        t               | _        | j                  d      | _        t        j                  j                  | j                        r| j                  | j                         t        j                  d| j                  d      z        D ]T  }t        j                  j                  |      r"t        j                  |      | j                  |<   | j                  |       V y )NzDir::Etc::sourcelistz	%s/*.listDir::Etc::sourceparts)r   filesfiles_mappingset	new_repos_apt_cfg_filedefault_fileospathisfileloadglobiglob_apt_cfg_dirislinkreadlink)selfr   files      r   __init__zSourcesList.__init__   s    
 ../EF 77>>$++,IId''( JJ{T->->?V-WWX 	Dww~~d#+-;;t+<""4(IIdO	r    c              #     K   | j                   j                         D ]  \  }}|D ]  \  }}}}}|s|||||f    yw)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comments           r   __iter__zSourcesList.__iter__   sT     !ZZ--/ 	<MD'6= <25'677FG;;<	<s   .??c                    d|v r|S t         j                  j                  t         j                  j                  | j	                  d      |            S )N/r*   )r1   r2   abspathjoinr7   )r:   filenames     r   _expand_pathzSourcesList._expand_path   s=    (?O77??277<<0A0ABY0Z\d#effr    c                     fd}d }t        j                  dd|      }t        j                  dd|      }|j                         D cg c]  }|t        vs| }} ||d         |d<   d |dj	                  |d d	             z  S c c}w )
Nc                    j                   j                  d   }||S dj                  t        j                  dd|       j                               S )NrJ   _z[^a-zA-Z0-9] )r   paramsrI   resubsplit)srJ   r:   s     r   _cleanup_filenamez8SourcesList._suggest_filename.<locals>._cleanup_filename  sG    {{))*5H#88BFF>3:@@BCCr    c                <    d| v r| j                  dd      } | d   } | S )N@   )rS   )rT   s    r   _strip_username_passwordz?SourcesList._suggest_filename.<locals>._strip_username_password  s&    axGGCObEHr    z
\[[^\]]+\] z\w+://r   z%s.listrO   rX   )rQ   rR   rS   VALID_SOURCE_TYPESrI   )r:   linerU   rZ   partpartss   `     r   _suggest_filenamezSourcesList._suggest_filename  s    	D	 vvmR.vviT* #'**,Q$$>P2PQQ ,E!H5a,SXXeBQi-@AAA Rs   
B	B	c                r   d}d}d}d}|j                         }|j                  d      rd}|dd  }|j                  d      }|dkD  r||dz   d  j                         }|d | }|j                         }|r.|j                         }|d   t        v rd}dj                  |      }|r|r|st        |      ||||fS )NFTr[   #rX   r   rO   )r   
startswithfindrS   r\   rI   r"   )	r:   r]   raise_if_invalid_or_disabledrA   rB   rC   rD   ichunkss	            r   _parsezSourcesList._parse  s    zz|??3G8D IIcNq51q56l((*G8D \\^Fay..&)'g%%gvw..r    c                    	 t         j                  j                  |       }|S # t        $ r# t         j                  j                  |       }Y |S w xY wzJ
        Wrapper for `apt_pkg` module for running with Python 2.5
        )apt_pkgconfig	find_fileAttributeErrorConfigFindFile)filespecresults     r   r/   zSourcesList._apt_cfg_file<  sL    
	7^^--h7F   	7^^,,X6F	7   # (AAc                    	 t         j                  j                  |       }|S # t        $ r# t         j                  j                  |       }Y |S w xY wrj   )rk   rl   find_dirrn   ro   FindDir)dirspecrr   s     r   r7   zSourcesList._apt_cfg_dirG  sL    
	5^^,,W5F   	5^^++G4F	5rs   c                    g }t        |d      }t        |      D ]1  \  }}| j                  |      \  }}}}	|j                  |||||	f       3 || j                  |<   y )Nr)open	enumeraterh   appendr+   )
r:   r;   groupfr@   r]   rA   rB   rC   rD   s
             r   r4   zSourcesList.loadR  sg    sO | 	?GAt.2kk$.?+E7FGLL!UGVW=>	? !

4r    c                   t        | j                  j                               D ]  \  }}|rt        j                  j                  |      \  }}	 t        j                  |       	 t        j                  d|z  |      \  }}t        j                  d      }	|D ]  \  }
}}}}g }|s|j!                  d	       |j!                  |       |r"|j!                  d
       |j!                  |       |j!                  d       dj#                  |      }	 |	j%                  |        || j&                  v r*| j                  j)                  | j&                  |          n| j                  j)                  |       || j*                  v se| j                  j,                  j/                  dt0              }| j                  j3                  ||d       | j                  |= t        j                  j5                  |      st        j6                  |        y # t        $ rT}t        j                  j                  |      s*| j                  j                  d|dt        |             Y d }~d }~ww xY w# t        t        f$ r6}| j                  j                  d|dt        |             Y d }~5d }~ww xY w# t        $ r6}| j                  j                  ddt        |             Y d }~_d }~ww xY w)NzFailed to create directory : z.%s-)prefixdirzUnable to create temp file at "z" for apt source: r   w#  # 
r[   zFailed to write to file modeF)listr+   r>   r1   r2   rS   makedirsOSErrorisdirr   r   r	   tempfilemkstempIOErrorfdopenr|   rI   writer,   atomic_mover.   rP   getDEFAULT_SOURCES_PERMset_mode_if_differentexistsremove)r:   rJ   r?   dfnexfdtmp_pather~   r@   rA   rB   rC   rD   rg   r]   	this_modes                     r   savezSourcesList.saveZ  sk   !%djj&6&6&8!9 +	(Hgh/2hKKN
{#+#3#36B;A#NLB IIb#&:A p6AugvwF"d+MM&)e,g.MM$'776?Dpp t111KK++Hd6H6H6RSKK++Hh? t~~- $ 2 2 6 6v?S TIKK55h	5QJJx(77>>(+IIh'W+	(
  h77==+--UVXabdXe.fgh  ) {KK))ijluvwlx.y)zz{" # p--V^`ijl`m2n-oopsI   H'I9K	I6"A	I11I69J>+J99J>	L 
+K;;L c                   i }| j                   j                         D ]  \  }}|s	g }|D ]  \  }}}}}	g }
|s|
j                  d       |
j                  |       |	r"|
j                  d       |
j                  |	       |
j                  d       |j                  dj                  |
              dj                  |      ||<    |S )Nr   r   r   r[   )r+   r>   r|   rI   )r:   
dumpstructrJ   r?   linesr@   rA   rB   rC   rD   rg   s              r   dumpzSourcesList.dump  s    
!%!1!1!3 	6Hg:A 	26AugvwF"d+MM&)e,g.MM$'LL1	2 (*wwu~
8$	6 r    c                    ||S |S Nr&   )r:   newolds      r   _choicezSourcesList._choice  s    ;J
r    Nc                    | j                   |   |   dd \  }}}}	||| j                  ||      | j                  ||      | j                  ||	      f| j                   |   |<   y)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.
        rX   N)r+   r   )
r:   r;   r@   rB   rC   rD   rA   enabled_old
source_oldcomment_olds
             r   modifyzSourcesList.modify  s|    
 7;jj6Fq6I!"6M3{J %g{)KT\\Z`blMmoso{o{  }D  FQ  pR  S

4r    c                   | j                   j                  d|d|d|       d}| D ]$  \  }}}}}	||k(  s| j                  ||d       d}& |s|| j                  }n| j	                  |      }|| j
                  vrg | j
                  |<   | j
                  |   }
|
j                  t        |
      dd||f       | j                  j                  |       y y )Nzadding source file: z | FT)rB   )
r   logr   r0   rK   r+   r|   lenr.   add)r:   
source_newcomment_newr;   foundrJ   r@   rB   rC   rD   r+   s              r   _add_valid_sourcezSourcesList._add_valid_source  s     	j+W[\]59 	1Ha&'#Ha6	
 |((((.4::%#%

4 JJt$ELL#e*dD*kJKNNt$ r    c                ~    | j                  |d      d   }| j                  |||xs | j                  |             y )NTre      )r;   )rh   r   r`   )r:   r]   rD   r;   rC   s        r   
add_sourcezSourcesList.add_source  sA    TEaH 	vwT5[T=S=STZ=[\r    c                l    | D ]/  \  }}}}}||k(  s|s| j                   |   j                  |       1 y r   )r+   pop)r:   rC   rJ   r@   rB   srcrD   s          r   _remove_valid_sourcez SourcesList._remove_valid_source  s<    26 	,.Ha#w}

8$((+	,r    c                R    | j                  |d      d   }| j                  |       y )NTr   r   )rh   r   r:   r]   rC   s      r   remove_sourcezSourcesList.remove_source  s'    TEaH!!&)r    )F)NNNr[   N)r#   r$   r%   r<   rE   rK   r`   rh   staticmethodr/   r7   r4   r   r   r   r   r   r   r   r   r&   r    r   r(   r(      su    $<gB2/>    !,(\$
S%.],*r    r(   c                  d     e Zd ZdZdZ fdZddZd Zd Zd Z	d Z
dd	Zd
 Zed        Z xZS )UbuntuSourcesListz-https://api.launchpad.net/1.0/~%s/+archive/%sz https://ppa.launchpadcontent.netc                z   || _         |j                  d   xs t        j                  | _        t        t
        |   |       | j                   j                  dd      | _        | j                   j                  dd      | _	        | j                  s*| j                  s| j                   j                  d       y y y )Ncodenamezapt-keyF)requiredgpgzDEither apt-key or gpg binary is required, but neither could be foundr   )r   rP   distror   superr   r<   r   apt_key_bingpg_binr   )r:   r   	__class__s     r   r<   zUbuntuSourcesList.__init__  s    j1DV__/7;;33I3N{{///FKK!!&l!m )5r    c                ,    t        | j                        S r   )r   r   )r:   memos     r   __deepcopy__zUbuntuSourcesList.__deepcopy__  s     --r    c                   | j                   ||fz  }t        d      }t        | j                  ||      \  }}|d   dk7  r"| j                  j	                  d|d   z         t        j                  t        |j                                     S )	Nzapplication/json)Accept)headersstatus   z.failed to fetch PPA information, error was: %sr   r   )	LP_APIdictr
   r   r   jsonloadsr	   read)r:   
owner_nameppa_namelp_apir   responseinfos          r   _get_ppa_infozUbuntuSourcesList._get_ppa_info  s~    
H5501"4;;H$>S KK!!&VY]^cYd&d!ezz)HMMO455r    c           	         |j                  d      d   }|j                  d      d   }	 |j                  d      d   }d| j                  d|d|d| j                  d	}|||fS # t        $ r d}Y 5w xY w)	N:rX   rG   r   ppazdeb z/ubuntu z main)rS   
IndexErrorPPA_URIr   )r:   r2   r   	ppa_ownerr   r]   s         r   _expand_ppazUbuntuSourcesList._expand_ppa  s|    jjoa IIcN1%		yy~a(H 15iSWS`S`aY((	  	H	s   A& &A43A4c                0   | j                   rxt        | j                        }t        |||||      }|| j                  _        | j                  j                  | j                   d|gd      \  }}}t        | xs d|v      }|S | j                  |      }|S )N)LANGLC_ALLLC_MESSAGESLC_CTYPELANGUAGEexportT)check_rcznothing exported)r   r   r   r   run_command_environ_updater   bool_gpg_key_exists)r:   key_fingerprintlocaleAPT_ENVr   outerrr   s           r   _key_already_existsz%UbuntuSourcesList._key_already_exists  s    -dkk:Fv6TZeklG5<DKK2;;22D4D4DhP_3`ko2pLBSSA$6c$ABE  ((9Er    c           
     &   d}dg}t         D ]d  }|j                  t        j                  |      D cg c]4  }|j	                  d      rt        j
                  j                  ||      6 c}       f |D ]X  }t        j
                  j                  |      s#	 | j                  j                  | j                  d|g      \  }}}	||v sUd} |S  |S c c}w # t        t        f$ r*}
| j                  d|dt        |
             Y d }
~
d }
~
ww xY w)NFz/etc/apt/trusted.gpg.z--list-packetszCould check key against file r   T)APT_KEY_DIRSextendr1   listdirrc   r2   rI   r   r   r   r   r   r   debugr	   )r:   r   r   keyfiles	other_dirxkey_filer   r   r   r   s              r   r   z!UbuntuSourcesList._gpg_key_exists  s   *+% 	rIOOIAVpA^_^j^jkn^oRWW\\)Q7pq	r ! 	Hww~~h'#';;#:#:DLLJZ\d;e#fLBS
 #c) E	  q  ) JJR[\]R^_`s#   C
"C
,CD& DDc           	     0   |j                  d      r| j                  |      \  }}}|| j                  v ry | j                  ||      }| j	                  |d         sd}| j
                  j                  sm| j                  r| j                  ddddd|d   g}	nt        D ]#  }
t        j                  j                  |
      s# n2 | j
                  j                  d	d
j                  t              z         
dt        j                  j                  |      j                  dd      d|d|d}| j                   dddd|d   g}	| j
                  j#                  |	dd       \  }}}|ryt%        |      dk(  r| j
                  j                  d|||	       	 t'        |d      5 }|j)                  |       d d d        | j
                  j+                  d|d   d|d       |xs  | j3                  |d| j4                        }n+| j7                  |d      d   }|xs | j3                  |      }| j9                  |||       y # 1 sw Y   xY w# t,        t.        f$ r2}| j
                  j                  d||t1        |             Y d }~d }~ww xY w)Nppa:signing_key_fingerprintr[   advz--recv-keysz--no-ttyz--keyserverzhkp://keyserver.ubuntu.com:80zNUnable to find any existing apt gpgp repo directories, tried the following: %sz, rG   rO   -z.gpgz--exportT)r   encodingr   z"Unable to get required signing key)r   r   stderrcommandwbzAdded repo key "z" for apt to file ""z)Unable to add required signing key for%s )r   r   r  errorrN   r   r   )rc   r   
repos_urlsr   r   r   r   r   r   r1   r2   r   r   rI   basenamereplacer   r   r   rz   r   r   r   r   r	   r`   r   rh   r   )r:   r]   rD   r;   rC   r   r   r   keyfiler	  keydirr   stdoutr  r~   r   s                   r   r   zUbuntuSourcesList.add_source  s   ??6"*.*:*:4*@'FIx(%%i:D ++D1J,KL {{--''#'#3#3UM:Wd  gF#'(A#B#D '3 ^F!ww~~f5 %^ !KK11  3C  FJ  FO  FO  P\  F]  3]  ^7=rww?O?OPV?W?_?_`ceh?iktv~"#'<<]Lkmwy}  X  zY  #Z)-)@)@SWbf)@)g&Bv;!+ KK116Z_ajp  {B1  CM!%gt!4 0 !0 KKOOZ^_xZy  |C  -D  E
 R411T4==2QRD[[D[I!LF9411&9Dvw50 0 !(1 M KK116afhqw  @I  JK  @L1  M  MMs0   I %I7-I II J#(JJc                    |j                  d      r| j                  |      d   }n| j                  |d      d   }| j                  |       y )Nr  r   Tr   r   )rc   r   rh   r   r   s      r   r   zUbuntuSourcesList.remove_sourceN  sH    ??6"%%d+A.F[[D[I!LF!!&)r    c                   g }| j                   j                         D ]f  }|D ]_  }|d   }|d   }|d   }|r|s|j                  d      r'| j                  |      \  }}}	|j	                  |       O|j	                  |       a h |S )NrX   r      r  )r+   valuesrc   r   r|   )
r:   _repositoriesparsed_reposparsed_reporA   rB   source_linerC   r   r   s
             r   r  zUbuntuSourcesList.repos_urlsU  s     JJ--/ 	6L+ 6#A%a.)!nG))&1262B2B;2O/FIx!((0!((56	6 r    r   r   )r#   r$   r%   r   r   r<   r   r   r   r   r   r   r   propertyr  __classcell__)r   s   @r   r   r     sM     =F0Gn.6	)006d*  r    r   c                   t        |j                               j                  | j                               D ]7  }t        j                  j                  |      s#t        j                  |       9 |j                          y)z4Revert the sourcelist files to their previous state.N)r-   keys
differencer1   r2   r   r   r   )sources_beforesources_aftersourceslist_beforerJ   s       r   revert_sources_listr#  j  s_     **,-889L9L9NO  77>>(#IIh  r    c                 
   t        t        t        dd      t        ddddg      t        d      t        d	dd
g      t        dd      t        dd      t        d      t        d	d      t        d	d      t        d      
      d      } | j                  }| j                  d   }| j                  d   }| j                  d   }d }t        sd}t	               r0| j                  dj                  |t        j                               ddg}t        |d      }|rt        |       | j                  r| j                  d|z         |d   rt        | |       n| j                  d|z         t        |d      }|rt        |       n0| j                  dj                  |t        j                               |s| j                  d       t        t        t        j                         rt#        |       }n| j                  d       t%        j&                  |      }	|j)                         }
	 |dk(  r|j+                  |       n|dk(  r|j-                  |       |j)                         }|
|k7  }g }t3               }t3               }|rt3        |j5                               j7                  |
j5                               }t3        |
j5                               j7                  |j5                               }| j8                  rct3        |j;                  |            D ]F  }|j=                  |
j?                  |d!      |j?                  |d!      |d"f||
v   |d"f||v   d#       H |r| j                  s	 d!}|jA                          |r| j                  j?                  d$      }| j                  j?                  d%      }tC        jD                  d&      d'z  }tG        jH                         }tK        |      D ]  }	 |jM                           n, t]        |
||	       d/| d0|r|nd1 }| j                  |       | jc                  ||||||2       y # t.        $ r)}| j                  d t1        |      z         Y d }~d }~ww xY w# tF        jN                  jP                  $ r0}|}| jS                  d(|d)z    d*t1        |       d+       Y d }~nd }~ww xY wd,|z  |z   }||kD  r||z   }tU        jV                  |       | jS                  d-tY        t[        |             d.       /# t^        t`        f$ r3}t]        |
||	       | j                  t1        |             Y d }~*d }~ww xY w)3NstrT)typer   presentabsent)r&  defaultchoicesraw)r&  r   zupdate-cache)r&  r)  aliasesint   )r&  r)     )
repostater   update_cacheupdate_cache_retriesupdate_cache_retry_max_delayrJ   r   validate_certsr   )argument_specsupports_check_moder0  r1  r2  zpython3-aptz+{0} must be installed and visible from {1}.r   z/usr/bin/python3z/usr/bin/pythonaptzX%s must be installed to use check mode. If run normally this module can auto-install it.r   z4%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.zInvalid repository string: %sr[   z	/dev/null)beforeafterbefore_headerafter_headerr3  r4  i  g     @@zFailed to update cache after rX   z due to z retry, retryingr   zSleeping for z5 seconds, before attempting to update the cache againz!Failed to update apt cache after z
 retries: zunknown reason)changedr0  sources_addedsources_removedr1  diff)2r   r   rP   HAVE_PYTHON_APTr   r   formatsys
executabler   r   r   r   
isinstancer   aptsources_distroDistributionr   copydeepcopyr   r   r   r"   r	   r-   r  r  _diffunionr|   r   r   secrets	randbelowr8  Cacheranger   cacheFetchFailedExceptionwarntimesleepr-  roundr#  r   r   	exit_json)r   rP   r0  r1  r2  sourceslistr   interpretersinterpreterr"  r   r   r!  r=  r@  r>  r?  rJ   r   r3  r4  	randomizerP  retryfetch_failed_excdelayr   s                              r   mainr^  u  s[   540E9x>ST5!64.AQR!%5!!<)-5")Eu%#>VT:u%
 !F" ]]F== DMM'"E==0L K %?!N!U!UVbdgdrdr!st*,=>3L%H;'  "TVb"c d &'v|4!WZf!fg 4L%H ;' !N!U!UVbdgdrdr!stPQ&+889'/PQ{3 %%'NNI""4(h%%d+  $$&M-GDEMeOM..01<<^=P=P=RSn1134??@R@R@TU<< 3 3O DE f~'9'9(B'G&3&7&7"&E/7.EhVdFd.e.6-DXUbEb-ce ff v(($	0C'-}}'8'89O'P$/5}}/@/@A_/`,#--d3f<			"#78 .E.$ (GYZ;<P;QQ["%3+;<>  $$$- W4}^muz  BF  Gu  N<y}LMMNB 9999 .;EAI; G""+,<"=!>>NP  J2E;; <y HJJu%KK-E%L0A/BBw xy ! 	0?QR2//	0s\   3-Q 7BT' <R.T' 	RQ??RS$&S
T' SAT' 'U)6(U$$U)__main__)0
__future__r   DOCUMENTATIONEXAMPLESRETURNrH  r5   r   r1   rQ   rL  rC  r   rS  ansible.module_utils.basicr    ansible.module_utils.common.filer   r   #ansible.module_utils.common.respawnr   r   r   +ansible.module_utils.common.text.convertersr	   ansible.module_utils.urlsr
   "ansible.module_utils.common.localer   r8  rk   aptsources.distror   rF  
get_distrorA  ImportErrorr   r\   r   	Exceptionr"   objectr(   r   r#  r^  r#   r&   r    r   <module>ro     s   #\|*X
,    	 	  
   4 Q l l A / G1)))+FO V' V	I 	h*& h*VX XvUGp zF O  155C5'5%Os   !B9 9C
C