a ì)g1 ã@szddlmZmZmZeZdZdZddlm Z ddl m Z ddl m Z mZddlmZmZddlmZdd lmZmZdd lZdd lZdd lZdd lZdd lZzdd lZd ZWneyÂd ZYn0zdd lZd Z Wneyêd Z Yn0z(dd l!m"Z"m#Z#ddl$m%Z%m&Z&d Z'Wne�y,d Z'Yn0ddl(m)Z)ddlm*Z*dZ+d a,Gdd„deƒZ-dd„Z.e/dk�rve.ƒd S)é)Úabsolute_importÚdivisionÚprint_functionaÌ. --- module: yum version_added: historical short_description: Manages packages with the I(yum) package manager description: - Installs, upgrade, downgrades, removes, and lists packages and groups with the I(yum) package manager. - This module only works on Python 2. If you require Python 3 support see the M(ansible.builtin.dnf) module. options: use_backend: description: - This module supports C(yum) (as it always has), this is known as C(yum3)/C(YUM3)/C(yum-deprecated) by upstream yum developers. As of Ansible 2.7+, this module also supports C(YUM4), which is the "new yum" and it has an C(dnf) backend. - By default, this module will select the backend based on the C(ansible_pkg_mgr) fact. default: "auto" choices: [ auto, yum, yum4, dnf ] type: str version_added: "2.7" name: description: - A package name or package specifier with version, like C(name-1.0). - Comparison operators for package version are valid here C(>), C(<), C(>=), C(<=). Example - C(name>=1.0) - If a previous version is specified, the task also needs to turn C(allow_downgrade) on. See the C(allow_downgrade) documentation for caveats with downgrading packages. - When using state=latest, this can be C('*') which means run C(yum -y update). - You can also pass a url or a local path to a rpm file (using state=present). To operate on several packages this can accept a comma separated string of packages or (as of 2.0) a list of packages. aliases: [ pkg ] type: list elements: str exclude: description: - Package name(s) to exclude when state=present, or latest type: list elements: str version_added: "2.0" list: description: - "Package name to run the equivalent of C(yum list --show-duplicates ) against. In addition to listing packages, use can also list the following: C(installed), C(updates), C(available) and C(repos)." - This parameter is mutually exclusive with I(name). type: str state: description: - Whether to install (C(present) or C(installed), C(latest)), or remove (C(absent) or C(removed)) a package. - C(present) and C(installed) will simply ensure that a desired package is installed. - C(latest) will update the specified package if it's not of the latest available version. - C(absent) and C(removed) will remove the specified package. - Default is C(None), however in effect the default action is C(present) unless the C(autoremove) option is enabled for this module, then C(absent) is inferred. type: str choices: [ absent, installed, latest, present, removed ] enablerepo: description: - I(Repoid) of repositories to enable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos, separate them with a C(","). - As of Ansible 2.7, this can alternatively be a list instead of C(",") separated string type: list elements: str version_added: "0.9" disablerepo: description: - I(Repoid) of repositories to disable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos, separate them with a C(","). - As of Ansible 2.7, this can alternatively be a list instead of C(",") separated string type: list elements: str version_added: "0.9" conf_file: description: - The remote yum configuration file to use for the transaction. type: str version_added: "0.6" disable_gpg_check: description: - Whether to disable the GPG checking of signatures of packages being installed. Has an effect only if state is I(present) or I(latest). type: bool default: "no" version_added: "1.2" skip_broken: description: - Skip all unavailable packages or packages with broken dependencies without raising an error. Equivalent to passing the --skip-broken option. type: bool default: "no" version_added: "2.3" update_cache: description: - Force yum to check if cache is out of date and redownload if needed. Has an effect only if state is I(present) or I(latest). type: bool default: "no" aliases: [ expire-cache ] version_added: "1.9" validate_certs: description: - This only applies if using a https url as the source of the rpm. e.g. for localinstall. If set to C(false), the SSL certificates will not be validated. - This should only set to C(false) used on personally controlled sites using self-signed certificates as it avoids verifying the source site. - Prior to 2.1 the code worked as if this was set to C(true). type: bool default: "yes" version_added: "2.1" sslverify: description: - Disables SSL validation of the repository server for this transaction. - This should be set to C(false) if one of the configured repositories is using an untrusted or self-signed certificate. type: bool default: "yes" version_added: "2.13" update_only: description: - When using latest, only update installed packages. Do not install packages. - Has an effect only if state is I(latest) default: "no" type: bool version_added: "2.5" installroot: description: - Specifies an alternative installroot, relative to which all packages will be installed. default: "/" type: str version_added: "2.3" security: description: - If set to C(true), and C(state=latest) then only installs updates that have been marked security related. type: bool default: "no" version_added: "2.4" bugfix: description: - If set to C(true), and C(state=latest) then only installs updates that have been marked bugfix related. default: "no" type: bool version_added: "2.6" allow_downgrade: description: - Specify if the named package and version is allowed to downgrade a maybe already installed higher version of that package. Note that setting allow_downgrade=True can make this module behave in a non-idempotent way. The task could end up with a set of packages that does not match the complete list of specified packages to install (because dependencies between the downgraded package and others can cause changes to the packages which were in the earlier transaction). type: bool default: "no" version_added: "2.4" enable_plugin: description: - I(Plugin) name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction. type: list elements: str version_added: "2.5" disable_plugin: description: - I(Plugin) name to disable for the install/update operation. The disabled plugins will not persist beyond the transaction. type: list elements: str version_added: "2.5" releasever: description: - Specifies an alternative release from which all packages will be installed. type: str version_added: "2.7" autoremove: description: - If C(true), removes all "leaf" packages from the system that were originally installed as dependencies of user-installed packages but which are no longer required by any such package. Should be used alone or when state is I(absent) - "NOTE: This feature requires yum >= 3.4.3 (RHEL/CentOS 7+)" type: bool default: "no" version_added: "2.7" disable_excludes: description: - Disable the excludes defined in YUM config files. - If set to C(all), disables all excludes. - If set to C(main), disable excludes defined in [main] in yum.conf. - If set to C(repoid), disable excludes defined for given repo id. type: str version_added: "2.7" download_only: description: - Only download the packages, do not install them. default: "no" type: bool version_added: "2.7" lock_timeout: description: - Amount of time to wait for the yum lockfile to be freed. required: false default: 30 type: int version_added: "2.8" install_weak_deps: description: - Will also install all packages linked by a weak dependency relation. - "NOTE: This feature requires yum >= 4 (RHEL/CentOS 8+)" type: bool default: "yes" version_added: "2.8" download_dir: description: - Specifies an alternate directory to store packages. - Has an effect only if I(download_only) is specified. type: str version_added: "2.8" install_repoquery: description: - If repoquery is not available, install yum-utils. If the system is registered to RHN or an RHN Satellite, repoquery allows for querying all channels assigned to the system. It is also required to use the 'list' parameter. - "NOTE: This will run and be logged as a separate yum transation which takes place before any other installation or removal." - "NOTE: This will use the system's default enabled repositories without regard for disablerepo/enablerepo given to the module." required: false version_added: "1.5" default: "yes" type: bool cacheonly: description: - Tells yum to run entirely from system cache; does not download or update metadata. default: "no" type: bool version_added: "2.12" extends_documentation_fragment: - action_common_attributes - action_common_attributes.flow attributes: action: details: In the case of yum, it has 2 action plugins that use it under the hood, M(ansible.builtin.yum) and M(ansible.builtin.package). support: partial async: support: none bypass_host_loop: support: none check_mode: support: full diff_mode: support: full platform: platforms: rhel notes: - When used with a C(loop:) each package will be processed individually, it is much more efficient to pass the list directly to the I(name) option. - In versions prior to 1.9.2 this module installed and removed each package given to the yum module separately. This caused problems when packages specified by filename or url had to be installed or removed together. In 1.9.2 this was fixed so that packages are installed in one yum transaction. However, if one of the packages adds a new yum repository that the other packages come from (such as epel-release) then that package needs to be installed in a separate task. This mimics yum's command line behaviour. - 'Yum itself has two types of groups. "Package groups" are specified in the rpm itself while "environment groups" are specified in a separate file (usually by the distribution). Unfortunately, this division becomes apparent to ansible users because ansible needs to operate on the group of packages in a single transaction and yum requires groups to be specified in different ways when used in that way. Package groups are specified as "@development-tools" and environment groups are "@^gnome-desktop-environment". Use the "yum group list hidden ids" command to see which category of group the group you want to install falls into.' - 'The yum module does not support clearing yum cache in an idempotent way, so it was decided not to implement it, the only method is to use command and call the yum command directly, namely "command: yum clean all" https://github.com/ansible/ansible/pull/31450#issuecomment-352889579' # informational: requirements for nodes requirements: - yum author: - Ansible Core Team - Seth Vidal (@skvidal) - Eduard Snesarev (@verm666) - Berend De Schouwer (@berenddeschouwer) - Abhijeet Kasurde (@Akasurde) - Adam Miller (@maxamillion) a - name: Install the latest version of Apache ansible.builtin.yum: name: httpd state: latest - name: Install Apache >= 2.4 ansible.builtin.yum: name: httpd>=2.4 state: present - name: Install a list of packages (suitable replacement for 2.11 loop deprecation warning) ansible.builtin.yum: name: - nginx - postgresql - postgresql-server state: present - name: Install a list of packages with a list variable ansible.builtin.yum: name: "{{ packages }}" vars: packages: - httpd - httpd-tools - name: Remove the Apache package ansible.builtin.yum: name: httpd state: absent - name: Install the latest version of Apache from the testing repo ansible.builtin.yum: name: httpd enablerepo: testing state: present - name: Install one specific version of Apache ansible.builtin.yum: name: httpd-2.2.29-1.4.amzn1 state: present - name: Upgrade all packages ansible.builtin.yum: name: '*' state: latest - name: Upgrade all packages, excluding kernel & foo related packages ansible.builtin.yum: name: '*' state: latest exclude: kernel*,foo* - name: Install the nginx rpm from a remote repo ansible.builtin.yum: name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state: present - name: Install nginx rpm from a local file ansible.builtin.yum: name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm state: present - name: Install the 'Development tools' package group ansible.builtin.yum: name: "@Development tools" state: present - name: Install the 'Gnome desktop' environment group ansible.builtin.yum: name: "@^gnome-desktop-environment" state: present - name: List ansible packages and register result to print with debug later ansible.builtin.yum: list: ansible register: result - name: Install package with multiple repos enabled ansible.builtin.yum: name: sos enablerepo: "epel,ol7_latest" - name: Install package with multiple repos disabled ansible.builtin.yum: name: sos disablerepo: "epel,ol7_latest" - name: Download the nginx package but do not install it ansible.builtin.yum: name: - nginx state: latest download_only: true )Ú AnsibleModule)Úget_best_parsable_locale)Ú has_respawnedÚrespawn_module)Ú to_nativeÚto_text)Ú fetch_url)ÚYumDnfÚyumdnf_argument_specNTF)Úfind_unfinished_transactionsÚfind_ts_remaining)Ú splitFilenameÚ compareEVR)Úcontextmanager)Ú fetch_filez.%{epoch}:%{name}-%{version}-%{release}.%{arch}cseZdZdZ‡fdd„Zdd„Zdd„Zedd „ƒZd d „Z d d „Z d7dd„Z e fdd„Z e fdd„Ze fdd„Zdd„Zdd„Zedd„ƒZdd„Zd8d!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zed-d.„ƒZd/d0„Zd1d2„Zed3d4„ƒZd5d6„Z ‡Z!S)9Ú YumModulez4 Yum Ansible module back-end implementation cs&tt|ƒ |¡d|_d|_d|_dS)NÚyumz/var/run/yum.pid)ÚsuperrÚ__init__Z pkg_mgr_nameÚlockfileÚ _yum_base)ÚselfÚmodule©Ú __class__©ú7/usr/lib/python3.9/site-packages/ansible/modules/yum.pyr½szYumModule.__init__c Csêt|jƒdkr|z|jj |jd¡Wqætjjyx}z6dt|ƒvr`|j j d|jdd�n|‚WYd}~qæd}~00nj|jD]b}z|jj |¡Wq‚tjjyâ}z.dt|ƒvrÊ|j   d|¡n|‚WYd}~q‚d}~00q‚dS)Nérzrepository not foundzRepository %s not found.©Úmsg) ÚlenÚ enablerepoÚyum_baseÚreposZ enableReporÚErrorsÚ YumBaseErrorr rÚ fail_jsonÚwarn)rÚeÚridrrrÚ _enablerepos_with_error_checkingÑs   z*YumModule._enablerepos_with_error_checkingc Cs¬�zxzt |j¡WYd}~YWdS|jjd||jt|ƒfd�WYd}~n d}~00Yn0Wn,t t f�y¦}zWYd}~dSd}~00d S) NÚrFz /proc/%d/statéÚZrz!Unable to check PID %s in %s: %sr!T)ÚopenrÚintÚreadlineÚ ValueErrorÚosÚunlinkÚgetpidÚsplitÚIOErrorÚkillÚOSErrorÚerrnoZESRCHrr)r )rÚfZoldpidÚstatr+rrrÚis_lockfile_pid_validås6.     &   >zYumModule.is_lockfile_pid_validc Csx|jr |jSt ¡|_d|jj_d|jj_d|jj_|j|jj_|j |jj_ |j r^|j |jj_ |j dkr€|j |jj_ |j |jj_ |jr tj |j¡r |j|jj_t ¡dkræt|jdƒrÄ|j ¡n"tj ¡}|jj |¡d|jj_|jrø|j|jj_|j|jj_|jjz(|jD]}|jj |¡�q|  ¡Wn<t!�yp}z"|j"j#dt$|ƒd�WYd}~n d}~00|jS)NrTú/Ú setCacheDirúFailure talking to yum: %sr!)%rrZYumBaseZpreconfZ debuglevelZ errorlevelÚpluginsÚ enable_pluginZenabled_pluginsÚdisable_pluginZdisabled_pluginsÚ releaseverÚ installrootÚrootÚconfÚ conf_filer5ÚpathÚexistsÚfnÚgeteuidÚhasattrrAZmiscZ getCacheDirr&ÚcacheÚdisable_excludesÚ sslverifyr%Ú disablerepoZ disableRepor-Ú Exceptionrr)r )rZcachedirr,r+rrrr%s@                    ,zYumModule.yum_basecCs,t|dƒr|jSd|j|j|j|j|jfS)NÚui_envraú%s:%s-%s-%s.%s)rOrUÚepochÚnameÚversionÚreleaseÚarch)rZporrrÚ po_to_envraCs zYumModule.po_to_envracCsª| ¡}tjdkr"|jjdd�}n |j ¡}|d}|D]*}| |j ¡¡s\| |j ¡¡r8dSq8tjdkr¦|d}|D]*}| |j ¡¡sž| |j ¡¡rzdSqzdS)N)ééT)Z return_evgrpsrr/F) ÚlowerrZ__version_info__r%Z doGroupListsÚendswithrXZgroupidZ environmentid)rrXZ name_lowerZ groups_listÚgroupsÚgroupZenvsÚenvrrrÚis_group_env_installedIs     z YumModule.is_group_env_installedNFc s,|dur d}|sžg}z<ˆjj |g¡\}}}||}|sN|sN| ˆj |¡¡Wn:tyŠ}z"ˆjjdt|ƒd�WYd}~n d}~00‡fdd„|DƒSt s²ˆjj ddd�a t d d ||g} d |vrÒ|   d ¡ˆj d krì|  dˆj g¡t ˆjƒ} t| | | d�} ˆjj| | d�\} } }| dk�rDd| v�rDˆjjd| |fd�d| v�rRd} dd„|  dd¡ d¡Dƒ}|�s¾|�s¾t d d |d|g} ˆj d k�r¦|  dˆj g¡ˆjj| | d�\}}}n d\}}}|dk�röd|v�röˆjjd| ||fd�d|v�rd}|dd„| dd¡ d¡Dƒ7}|SgS)Nz/%{epoch}:%{name}-%{version}-%{release}.%{arch} rBr!csg|]}ˆ |¡‘qSr©r\©Ú.0Úp©rrrÚ nóz*YumModule.is_installed..ÚrpmT©Úrequiredz-qú--qfÚ*ú-ar@z--root©ÚLANGÚLC_ALLÚ LC_MESSAGES©Zenviron_updaterzis not installedzError from rpm: %s: %sÚcSsg|]}| ¡r|‘qSr©Ústriprfrrrrj„rkz(none)Ú0Ú ú--whatprovides©rrwrwzno package providescSsg|]}| ¡r|‘qSrrxrfrrrrj‘rk)r%ÚrpmdbÚmatchPackageNamesÚextendÚreturnInstalledPackagesByDeprTrr)r ÚrpmbinÚ get_bin_pathÚappendrGrÚdictÚ run_commandÚreplacer8)rÚrepoqÚpkgspecÚqfÚis_pkgÚpkgsr+ÚmÚ_ÚcmdÚlocaleÚlang_envÚrcÚoutÚerrÚrc2Úout2Úerr2rrirÚ is_installed`sP,         zYumModule.is_installedc s8|sŽg}z8ˆjj |g¡\}}}||}|s>| ˆj |¡¡Wn:tyz}z"ˆjjdt|ƒd�WYd}~n d}~00‡fdd„|DƒSt |ƒ}dd  ˆj ¡g} | | ¡dd  ˆj ¡g} | | ¡ˆj rà| dˆj ¡|d ||g} ˆj | ¡\} } } | d k�rd d„|  d ¡DƒSˆjjd | | fd�gS)NrBr!csg|]}ˆ |¡‘qSrrerfrirrrj¢rkz*YumModule.is_available..ú --disablerepoú,ú --enablerepoú--releasever=%srorcSsg|]}| ¡r|‘qSrrxrfrrrrj³rkr{úError from repoquery: %s: %s)r%ÚpkgSackrr€ÚreturnPackagesByDeprTrr)r ÚlistÚjoinrSr$rFr†r8)rrˆr‰rŠrŒr+r�rŽÚmyrepoqÚr_cmdr�r’r“r”rrirÚ is_available–s.,   zYumModule.is_availablec sr|s¾g}g‰zNˆj |¡ˆj |¡}|sHˆjj |g¡\}}}||}ˆjjdd�j‰Wn:ty”}z"ˆjj dt |ƒd�WYd}~n d}~00‡fdd„|Dƒ}t ‡fdd„|DƒƒSt |ƒ} dd   ˆj¡g} |  | ¡d d   ˆj¡g} |  | ¡ˆj�r|  d ˆj¡| d d ||g} ˆj | ¡\} } }| dk�rVt dd„|  d¡DƒƒSˆjj d| |fd�t ƒS)NÚupdates)Z pkgnarrowrBr!c3s|]}|ˆvr|VqdS©Nr©rgÚpkg)r¥rrÚ Érkz&YumModule.is_update..c3s|]}ˆ |¡VqdSr¦rerfrirrr©Ërkr™ršr›rœz--pkgnarrow=updatesrorcss|]}| ¡r|VqdSr¦rxrfrrrr©Ürkr{r�)r%rŸr�ržrZdoPackageListsr¥rTrr)r Úsetr r¡rSr€r$rFr†r8)rrˆr‰rŠrŒr+r�rŽZretpkgsr¢r£r�r’r“r”r)rr¥rÚ is_update¹s8  ÿ,   zYumModule.is_updatec sp|�spg}�zzˆj |¡ˆj |¡}Wnˆty²}zpdt|ƒvrœˆjrlˆj ˆjdddˆjg¡nˆj ˆjddg¡ˆj |¡ˆj |¡}n‚WYd}~n d}~00|�sˆjj   |g¡dd…\}}|  |¡|  |¡ˆjj   |g¡dd…\}}|  |¡|  |¡Wn<t�yX}z"ˆjj dt|ƒd�WYd}~n d}~00t‡fd d „|DƒƒSt|ƒ}d d  ˆj¡g} |  | ¡d d  ˆj¡g} |  | ¡ˆj�rÄ|  dˆj¡|d|d|g} ˆj | ¡\} } } |d||g} ˆj | ¡\}}}| dk�rP|dk�rP| |7} dd„|  d¡Dƒ}|�sLˆj|||d�}|Sˆjj d| | |fd�tƒS)Nz*repomd.xml signature could not be verifiedZ makecacheZfastrœrr/rBr!c3s|]}ˆ |¡VqdSr¦rerfrirrr©rkz*YumModule.what_provides..r™ršr›ror|cSsh|]}| ¡r|’qSrrxrfrrrÚ rkz*YumModule.what_provides..r{©rŠr�)r%rŸr�rTr rFrr†Ú yum_basecmdržrr€r~r)rªr r¡rSr$r8r˜)rrˆZreq_specrŠrŒr+Z exact_matchesZ glob_matchesr¢r£r�r’r“r”r•r–r—rrirÚ what_providesâsZ  ÿ    ÿ   ,  zYumModule.what_providescCs¦g}ts |Sdd„|Dƒ}tƒ}|D]|}t|ƒ}|D]j}|\}} t| ƒ\} } } } }|D]F}d| |f}| |dkrV||dkrV||vr˜| d| |f¡q4qVq4q$|S)zr checks the package list to see if any packages are involved in an incomplete transaction css|]}t|ƒVqdSr¦)rr§rrrr©+rkz/YumModule.transaction_exists..z%s-%srr^)Útransaction_helpersrrrr„)rÚpkglistÚ conflictsZpkglist_nvreasZunfinished_transactionsZtransZstepsÚstepÚactionZ step_specÚnÚvr.r+Úar¨ZlabelrrrÚtransaction_existss"  zYumModule.transaction_existsc Cs¶t ¡}| tj¡t |tj¡}zRz| |¡}Wn4tjyf}zWYd}~Wt  |¡dSd}~00Wt  |¡n t  |¡0d|tj p�d|tj |tj |tj |tjfS)z%return envra of a local rpm passed inNrVrz)rlZTransactionSetZ setVSFlagsZ_RPMVSF_NOSIGNATURESr5r1ÚO_RDONLYZ hdrFromFdnoÚerrorÚcloseZ RPMTAG_EPOCHZ RPMTAG_NAMEZRPMTAG_VERSIONZRPMTAG_RELEASEZ RPMTAG_ARCH)rrKÚtsÚfdÚheaderr+rrrÚ local_envraDs"   þ ûzYumModule.local_envrac csþd}ddg}t d¡t d¡g}�zxzü|jjj�r|jjjdv�r|jjjr‚||jjj}|jjj}|jjjrÆ|d|jjj}nDd|jjjvrÆ|jjj d¡d  d ¡d }|jjj d   |¡d¡}|rú|d}|D] }t   d d||¡tj |d<qÖn|D]}|jjjtj |d<qþdVWnt jj�y:‚Yn0W|D]&}t d  |¡¡�rBtj d  |¡=�qB|d �r‚|d tj d<|d�rú|dtj d<n^|D]&}t d  |¡¡�r tj d  |¡=�q |d �rà|d tj d<|d�rø|dtj d<0dS)NrwÚhttpÚhttpsZ http_proxyZ https_proxy)Z_none_ú:ú@rz//éÿÿÿÿz{0}@z (http://)z\g<1>Ú_proxyz {0}_proxyr )r5Úgetenvr%rIÚproxyZproxy_usernameZproxy_passwordr8r‡ÚformatÚreÚsubÚenvironrr'r()rZnamepassÚschemeZ old_proxy_envZ proxy_urlÚitemrrrÚ set_env_proxyYsN   þ    ú  zYumModule.set_env_proxyc Csv| ¡r.| d¡dkr.| d¡\}}}}}}nd|iS||||||d|||||fdœ}|dkrjd|d<nd|d<|S) Nú|éZ error_parsingrV)rXr[rWrZrYÚrepoÚenvraÚ installedZyumstateÚ available)ryÚcountr8) rZpkgstrrµr+r¶r.r·rÑÚdrrrÚ pkg_to_dict‚sù  zYumModule.pkg_to_dictú %{repoid}cCs`|d|dg}|jr&| d|jg¡|j |¡\}}}|dkrXtdd„| d¡DƒƒSgSdS)Nrorqrœrcss|]}| ¡r|VqdSr¦rxrfrrrr©Ÿrkz%YumModule.repolist..r{)rFr€rr†rªr8)rrˆrŠr�r’r“rŽrrrÚrepolist™szYumModule.repolistcs\d}d}|dddg}ˆjr0| dd ˆj¡g¡ˆjrL| dd ˆj¡g¡ˆjd krf| d ˆjg¡ˆjrˆtj ˆj¡rˆ|d ˆjg7}|d kr²‡fd d„t ˆj |d|d�ƒDƒS|dkr܇fdd„t ˆj |d|d�ƒDƒS|dk�r‡fdd„t ˆj |d|d�ƒDƒS|dk�r*dd„t ˆ  |¡ƒDƒS‡fdd„t ˆj |||d�ˆj |||d�ƒDƒS)Nz8%{name}|%{epoch}|%{version}|%{release}|%{arch}|%{repoid}z9%{name}|%{epoch}|%{version}|%{release}|%{arch}|installed ú--show-duplicatesú --pluginsú--quietr™ršr›r@ú --installrootú-crÓcsg|]}| ¡rˆ |¡‘qSr©ryr×rfrirrrj³rkz(YumModule.list_stuff..rqr­r¥csg|]}| ¡rˆ |¡‘qSrrßrfrirrrj¶rkrÔcsg|]}| ¡rˆ |¡‘qSrrßrfrirrrj¹rkr&cSs g|]}| ¡rt|dd�‘qS)Zenabled)ÚrepoidÚstate)ryr…)rgrXrrrrj¼rkcsg|]}| ¡rˆ |¡‘qSrrßrfrirrrj¾sþ)rSr€r¡r$rGrJr5rKrLÚsortedr˜r«r¤rÙ)rÚ repoquerybinÚstuffrŠZis_installed_qfrˆrrirÚ list_stuff£s,  "" "  "þzYumModule.list_stuffc Cs˜|j|g|}|jr(| d|jg¡|js<| ddg¡|jjrb|jjd|dt|d�d�nt|d�|d<t|jƒ}t|||d �}|jj ||d �\}} } |d krê|D]>} d | vrªd | | vsÎd| | vrªd| } |jj d| |d�qª||d<|d  | ¡|d| 7<d|d<d| v�r,|dk�s6d| v�r>d|d<|dk�rbd|d<|jj fi|¤Žd| �pl| v�r”d|d<d|d<|jj fi|¤Ž|S)Nrœz--setoptz sslverify=0TÚresults)rÓ©ÚchangedræÚchangesrérrrvr ú://zNo package %s available.zCannot open: %s. Skipping.z$Package at %s could not be installedF)rèr"r’r’r"rèz Nothing to dorzdoes not have any packageszNo space left on device) r®rFr€rRrÚ check_modeÚ exit_jsonr…rr†r)r„) rÚitemsr´rŒÚresr�r�r‘r’r“r”ÚspecrrrÚ exec_installÄs<   zYumModule.exec_installc( CsÚg}g}i}g|d<d|d<d|d<d|d<|D�]v}d}d}| d¡sRd |v�rˆd |vr¦tj |¡s¦|dd |7<|d d |¡d |d<|jjfi|¤Žd |v�r| ¡�>t|j|ƒ} |  d¡sèd | } t  | | ¡| } Wdƒn1sü0Yn|} |  | ¡} | du�r2|jjd |d�|  || ¡} | �r`|d d| d| f¡q0t | ƒ\} }}}}|  || ¡} t | ƒdk�rt | dƒ\}}}}}t | dƒ\}}}}}|�pÀd}|�pÊd}t|||f|||fƒ}|dk�r||k�r| D]}| |¡�rú|g} �qút | ƒdk�r€| d}t |ƒ\}}} }!}"|!�pDd}!t|!|| f|||fƒ}|dk�rt|j�rtd}n |dk�r€q0| }�nü| d¡�rª| |¡�r¢q0|}�nÚtddgƒ t|ƒ¡�sô|j ||dd�} | �rô|d d| d|f¡q0| ||¡}#|#�sF|dd|7<|d d|¡d|d<|jjfi|¤Ž| |#¡}$|$�rŠ|ddd |$¡7<d|d<|jjfi|¤Žd}%|#D]8}&|j ||&dd��r’d}%|d d|&|f¡�qÌ�q’|%�sö|  ||¡�röd}%|d d|¡|%�rþq0|j�r€|#D]t} t | ƒ\} }}}}|j || dd�}'|'�r t |'dƒ\}}} }!}"t|!|| f|||fƒ}|dk�rrd}n d}�q€�q |}|�rž|j�rž| |¡q0| |¡q0|�rÀ| |d||¡}|�rÖ| |d||¡}|S) Nrærwr"rr’Frèú.rpmrêú)No RPM file matching '%s' found on systeméz%s.rpmú4Failed to get envra information from RPM package: %sr!z$%s providing %s is already installedr/r rzTrÃrpú?©r‹ú>No package matching '%s' found available, installed or updatedé~ú4The following packages have pending transactions: %sú, é}z)package providing %s is already installedZ downgradeÚinstall)r`r5rKrLr„rr)rÎrÚrenamer¿r˜rr#rZallow_downgradeÚ startswithrdrªÚ intersectionr¯r¸r¡rð)(rrírˆrŒZdowngrade_pkgsrîrïr¨Zdowngrade_candidateÚpackageZnew_package_pathrÒZinstalled_pkgsrXZverÚrelrWr[Z cur_name0Zcur_ver0Zcur_rel0Z cur_epoch0Z cur_arch0Z cur_name1Zcur_ver1Zcur_rel1Z cur_epoch1Z cur_arch1ZcompareZ installed_pkgZcur_nameZcur_verZcur_relZ cur_epochZcur_archr±r²ÚfoundÚthisZ inst_pkgsrrrrüúsÒ      $                   zYumModule.installc Cs°g}i}g|d<d|d<d|d<d|d<|D]H}| d¡rF| |¡}n | ||¡}|rb| |¡q,|d d |¡q,|�r¬|jjr¢|jjd |dt|d �d �nt|d �|d <|jrÈ|j dg|}n|j dg|}|j  |¡\}} } ||d<|d | ¡| |d<|dk�rF|j�r4d| v�r4|jj dd�n|jj fi|¤Žd|_ |D]R}| d¡�rl| |¡}n|j||d d�}|�rPd||d<|jj fi|¤Ž�qPd |d<|S)Nrærwr"Frèrr’rÃz%s is not installedT)ÚremovedrçréÚ autoremoveÚremovezNo such commandzJVersion of YUM too old for autoremove: Requires yum 3.4.3 (RHEL/CentOS 7+)r!röz!Package '%s' couldn't be removed!) rþrdr˜r„rrërìr…rr®r†r)r) rrírˆrŒrîr¨rÓr�r’r“r”rrrr§sL        zYumModule.removecCsR|jr.|j |jdgd|jg¡\}}}n|j |jdg¡\}}}|||fS)Nz check-updaterœ)rFrr†r®)rr’r“r”rrrÚrun_check_updateês(zYumModule.run_check_updatecCs"d dd„| ¡Dƒ¡}t dd|¡}i}i}| d¡D]à}| ¡}d|vs8t|ƒdvs8d|d vrfq8|d |d |d }}}| dd ¡\}} ||vr¢g||<|| || |d œ¡t|ƒd kr8|d|d|d} } } |  dd ¡\} }| |v�rg|| <||  | || d œ¡q8||fS)Nr{css|]}|r|VqdSr¦r)rgÚlrrrr©õrkz/YumModule.parse_check_update..z \n\W+(.*)z \1rp)r]éÚ.rr r/)rYÚdistrÑr r]r^rÐ)r¡Ú splitlinesrÉrÊr8r#Úrsplitr„)Zcheck_update_outputr“r¥Ú obsoletesÚliner¨rYrÑrXr Z obsolete_pkgZobsolete_versionZ obsolete_repoZ obsolete_nameZ obsolete_distrrrÚparse_check_updateòs(   zYumModule.parse_check_updatec CsÔi}g|d<d|d<d|d<d|d<i}g|d<g|d <i}i}d}|jdd…}d |vr^d }| ¡\} } } | dkrŠ|rŠ|d d ¡|S| d kr¢| | ¡\}}n*| dkrÌ| |d<| |d<|jjfi|¤Ž|rð| d¡t| ¡ƒ} tƒ} �n:tƒ} tƒ} |D�]&}|  d¡�r.|d |¡|   |¡�q|  d¡�rèd|v�rèt j  |¡�s’|dd|7<|d d|¡d|d<|jjfi|¤Ž| |¡}|du�r¸|jjd|d�| ||¡�rÖ|d |¡n|d  |¡�qd|v�r~| ¡�t|j|ƒ}Wdƒn1�s0Y| |¡}|du�rN|jjd|d�| ||¡�rl|d |¡n|d  |¡�q| ||¡�rœ|d |¡n|d  |¡| ||¡}|�sü|dd|7<|d d|¡d|d<|jjfi|¤Žd }|D]|}||d v�r.| ||¡�r.d}�q‚t|ƒ\}}}}}||dv�r||v�rd}|   |¡||k�rx|| |<�q‚�q| ||¡�s®|j�r®|d d|¡�q|�rÊ|d d|¡�q| |¡}|�r|ddd |¡7<|d dd |¡¡d|d<|jjfi|¤Ž�qg}| D]œ}|  d¡�rR| |df¡nz||v�r˜| |}||d}| |d||d|d|d ff¡n4||D]*}| |d!|d|d|d ff¡�q �q2|j�rêtg|d"�|d#<nt|d |d"�|d#<|�r ||d$<|jj�r2| �s&|d �r.d |d<|S|j�rL| d%|jg¡|�rp|j |¡\} } } d |d<�n,|j�r|d�rð|dg|d7}t|jƒ}t|||d&�}|jj||d'�\} } } |  ¡ ¡}|  d(¡�sþ|  d)¡�sþd |d<ngd*¢\} } } nœ|d �s| �rŽ|j�sŽ|d g|d |d7}t|jƒ}t|||d&�}|jj||d'�\} } } |  ¡ ¡}|  d(¡�sœ|  d)¡�sœd |d<ngd*¢\} } } | |d<|d| 7<|d | ¡| �rÐd |d+<|S),Nrærwr"Frèrr’ÚupdaterürpTz/Nothing to do here, all packages are up to dateédr rÃrñrêròrórôr!r÷røz@Packages providing %s not installed due to update_only specifiedz(All packages providing %s are up to daterùrúé€z&because of (at least) %s-%s.%s from %srYr rÑz %s.%s from %s)rÓÚupdatedrérrœrrrvzno packages marked for updatez nothing to dor}Zfailed) r®rr„rrr)rªÚkeysr…rþÚaddr`r5rKrLr¿r˜rÎrr¯r¤rÚ update_onlyr¸r¡rërFr€r†rryr_)rrírˆrîrŒr¥rZ update_allr�r’r“r”Z will_updateZwill_update_from_other_packagerïrÒrr±Z nothing_to_dor¨ZpkgnamerŽr²Z to_updateÚwZ other_pkgr�r‘Z out_lowerrrrÚlatest sB           ,          üþÿ ýþÿ       ÿ    ÿ zYumModule.latestc Csx|j}|js|jrg}d|_|jrVtj |j¡rV|jd|jg7_|rV|d|jg7}|jrj|j  dg¡|j rŠ|j  dd  |j ¡g¡|j rª|j  dd  |j ¡g¡|j rÈ|j  dd  |j ¡g¡|jræ|j  dd  |j¡g¡|j�r d d  |j¡g}|j  |¡|j�r(|j  d |jg¡|j�r>|j  d g¡|j�rp|j  d g¡|j�rp|j  d |jg¡|j�rŒ|j  d|jg¡|jdk�r°d|jg}|j  |¡|jdv�rº|j�rÚ|j |jddg¡zž|jjj ¡}|j �rvzB|jjj ¡}|D]&}||v�r|jj |¡}|jj}�q|}Wn@tj j!�yt} z"|jj"dt#| ƒd�WYd} ~ n d} ~ 00Wn@tj j!�y¸} z"|jj"dt#| ƒd�WYd} ~ n d} ~ 00|jdk�sÎ|j$�r|j%�râ|j &d¡|j'�rö|j &d¡|j(�r |j &d¡| )||¡} n\|jdv�rF|j%�r8|j &d¡| *||¡} n.|jdv�r`| +||¡} n|jj"dddd d!�| S)"NÚabsentrÞz --skip-brokenz--disablerepo=%sršz--enablerepo=%sz--enablepluginz--disablepluginz --exclude=%sz--disableexcludes=%sz --cacheonlyz--downloadonlyz--downloaddir=%srœr@z--installroot=%s)rÓÚpresentrÚcleanú expire-cachez!Error setting/accessing repos: %sr!zError accessing repos: %srz --nogpgcheckz --securityz--bugfix)rÓr)rrz/we should never get here unless this all failedFrwzunexpected state)r"rèræÚerrors),ÚnamesrrárJr5rKrLr®Z skip_brokenr€rSr¡r$rDrEZexcluderQZ cacheonlyZ download_onlyZ download_dirrFrGÚ update_cacherr†r%r&rZgetRepoZrepoXMLràrr'r(r)r rZdisable_gpg_checkr„ZsecurityZbugfixrrür) rrˆrŒZe_cmdZ current_reposZ new_reposÚir,r·r+rîrrrÚensures�        0,      üzYumModule.ensurecCstSr¦)ÚHAS_YUM_PYTHONrrrrÚhas_yum”szYumModule.has_yumc Cs trts tjdkr tƒs tdƒg}ts2| d¡ts@| d¡| ¡|r`|jj d  |¡d�|j  d¡rz|j  d¡}n |j  d¡}|dd d g|_ |j rö|jsö|jsö|j |j d d g¡\}}}|d krà|jjdd|gd�n|jjdd||gd�|jj ddd�}|j�rp|�sp|jj�sp|j  d¡}|�r`|j�rP|j d||jf¡n|j d|¡|jj ddd�}|j�r¢|�sŒ|jj dd�d| ||j¡i}�nTd} z|jjj} Wnt�yÊY�n0d| v�rÎ|�rÎ|dddg} |jdk�r|  d|jg¡|j�rÎzttdd ƒ�} |  ¡} Wdƒn1�s80Ytj |jj!dd!�} |j "| j#¡|  $d"d#„| Dƒ¡|  %¡Wn<t&�y¼}z"|jj d$t'|ƒd�WYd}~n d}~00|  d%| j#g¡| (| ¡}| �röd&| )d'd(¡d)f|d'<|jjfi|¤ŽdS)*z: actually execute the module code backend z/usr/bin/pythonzThe Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.zxThe Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.z. r!zyum-deprecatedrz-dÚ2z-yrrrFz Cache updated)rèr"r’ræzFailed to update cacheÚ repoqueryrmz'%s -y install yum-utils --releasever %sz%s -y install yum-utilszZrepoquery is required to use list= with this module. Please install the yum-utils package.ræNZ rhnpluginrÚrÛrÜr@rÝz /etc/yum.confr.)ÚdirÚdeletecSsg|]}| d¡s|‘qS)zexclude=)rþ)rgÚcrrrrjòrkz!YumModule.run..z Failure setting up repoquery: %srÞz%s %sr"rwzxWarning: Due to potential bad behaviour with rhnplugin and certificates, used slower repoquery calls instead of Yum API.)*ÚHAS_RPM_PYTHONr#ÚsysÚ executablerrr„Z wait_for_lockrr)r¡rƒr®r rr r†rìZinstall_repoqueryrërFrår%rCZ_pluginsÚAttributeErrorrGr€rQr1Ú readlinesÚtempfileZNamedTemporaryFileZtmpdirZadd_cleanup_filerXÚ writelinesr»rTr r"Úget)rZ error_msgsZyumbinr’ÚstdoutÚstderrrãZyum_pathrær&Z yum_pluginsr=ZcontentZ tmp_conf_filer+rrrÚrun˜sŠ    üü     ( ,  þ z YumModule.run)NF)rØ)"Ú__name__Ú __module__Ú __qualname__Ú__doc__rr-r?Úpropertyr%r\rdr˜Údef_qfr¤r«r¯r¸r¿rrÎr×rÙrårðrürrÚ staticmethodrrr"r$r4Ú __classcell__rrrrr¸s@ * 3 6 # ) =% ( !6.C -{z rcCs:tdgd¢d�tdd<tfit¤Ž}t|ƒ}| ¡dS)NÚauto)r=rZyum4Zdnf)ÚdefaultÚchoicesZ argument_specZ use_backend)r…r rrr4)rZmodule_implementationrrrÚmains ÿr@Ú__main__)0Z __future__rrrÚtypeZ __metaclass__Z DOCUMENTATIONZEXAMPLESZansible.module_utils.basicrZ"ansible.module_utils.common.localerZ#ansible.module_utils.common.respawnrrZansible.module_utils._textr r Zansible.module_utils.urlsr Zansible.module_utils.yumdnfr r r<r5rÉr+r/rlr*Ú ImportErrorrr#Zyum.miscrrZrpmUtils.miscutilsrrr°Ú contextlibrrr:r‚rr@r5rrrrÚ sd%a          U