
    Vh@                        d dl mZ dZdZd dlZd dlZd dlmZmZ d dl	m
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mZ da G d de      Zd Zedk(  r e        yy)    )annotationsa*  
---
module: dnf
version_added: 1.9
short_description: Manages packages with the I(dnf) package manager
description:
     - Installs, upgrade, removes, and lists packages and groups with the I(dnf) package manager.
options:
  use_backend:
    description:
      - Backend module to use.
    default: "auto"
    choices:
        auto: Automatically select the backend based on the C(ansible_facts.pkg_mgr) fact.
        yum: Alias for V(auto) (see Notes)
        dnf: M(ansible.builtin.dnf)
        yum4: Alias for V(dnf)
        dnf4: Alias for V(dnf)
        dnf5: M(ansible.builtin.dnf5)
    type: str
    version_added: 2.15
  name:
    description:
      - "A package name or package specifier with version, like C(name-1.0).
        When using state=latest, this can be '*' which means run: dnf -y update.
        You can also pass a url or a local path to an rpm file.
        To operate on several packages this can accept a comma separated string of packages or a list of packages."
      - Comparison operators for package version are valid here C(>), C(<), C(>=), C(<=). Example - C(name >= 1.0).
        Spaces around the operator are required.
      - You can also pass an absolute path for a binary which is provided by the package to install.
        See examples for more information.
    aliases:
        - pkg
    type: list
    elements: str
    default: []

  list:
    description:
      - Various (non-idempotent) commands for usage with C(/usr/bin/ansible) and I(not) playbooks.
        Use M(ansible.builtin.package_facts) instead of the O(list) argument as a best practice.
    type: str

  state:
    description:
      - Whether to install (V(present), V(latest)), or remove (V(absent)) a package.
      - Default is V(None), however in effect the default action is V(present) unless the O(autoremove=true),
        then V(absent) is inferred.
    choices: ['absent', 'present', 'installed', 'removed', 'latest']
    type: str

  enablerepo:
    description:
      - C(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 ",".
    type: list
    elements: str
    default: []

  disablerepo:
    description:
      - C(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(,).
    type: list
    elements: str
    default: []

  conf_file:
    description:
      - The remote dnf configuration file to use for the transaction.
    type: str

  disable_gpg_check:
    description:
      - Whether to disable the GPG checking of signatures of packages being
        installed. Has an effect only if O(state=present) or O(state=latest).
      - This setting affects packages installed from a repository as well as
        "local" packages installed from the filesystem or a URL.
    type: bool
    default: 'no'

  installroot:
    description:
      - Specifies an alternative installroot, relative to which all packages
        will be installed.
    version_added: "2.3"
    default: "/"
    type: str

  releasever:
    description:
      - Specifies an alternative release from which all packages will be
        installed.
    version_added: "2.6"
    type: str

  autoremove:
    description:
      - If V(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 O(state=absent).
    type: bool
    default: "no"
    version_added: "2.4"
  exclude:
    description:
      - Package name(s) to exclude when O(state=present), or latest. This can be a
        list or a comma separated string.
    version_added: "2.7"
    type: list
    elements: str
    default: []
  skip_broken:
    description:
      - Skip all unavailable packages or packages with broken dependencies
        without raising an error. Equivalent to passing the C(--skip-broken) option.
    type: bool
    default: "no"
    version_added: "2.7"
  update_cache:
    description:
      - Force dnf to check if cache is out of date and redownload if needed.
        Has an effect only if O(state=present) or O(state=latest).
    type: bool
    default: "no"
    aliases: [ expire-cache ]
    version_added: "2.7"
  update_only:
    description:
      - When using latest, only update installed packages. Do not install packages.
      - Has an effect only if O(state=present) or O(state=latest).
    default: "no"
    type: bool
    version_added: "2.7"
  security:
    description:
      - If set to V(true), and O(state=latest) then only installs updates that have been marked security related.
      - Note that, similar to C(dnf upgrade-minimal), this filter applies to dependencies as well.
    type: bool
    default: "no"
    version_added: "2.7"
  bugfix:
    description:
      - If set to V(true), and O(state=latest) then only installs updates that have been marked bugfix related.
      - Note that, similar to C(dnf upgrade-minimal), this filter applies to dependencies as well.
    default: "no"
    type: bool
    version_added: "2.7"
  enable_plugin:
    description:
      - C(Plugin) name to enable for the install/update operation.
        The enabled plugin will not persist beyond the transaction.
    version_added: "2.7"
    type: list
    elements: str
    default: []
  disable_plugin:
    description:
      - C(Plugin) name to disable for the install/update operation.
        The disabled plugins will not persist beyond the transaction.
    version_added: "2.7"
    type: list
    default: []
    elements: str
  disable_excludes:
    description:
      - Disable the excludes defined in DNF config files.
      - If set to V(all), disables all excludes.
      - If set to V(main), disable excludes defined in C([main]) in C(dnf.conf).
      - If set to V(repoid), disable excludes defined for given repo id.
    version_added: "2.7"
    type: str
  validate_certs:
    description:
      - This only applies if using a https url as the source of the rpm. For example, for localinstall.
        If set to V(false), the SSL certificates will not be validated.
      - This should only set to V(false) used on personally controlled sites using self-signed certificates as it avoids verifying the source site.
    type: bool
    default: "yes"
    version_added: "2.7"
  sslverify:
    description:
      - Disables SSL validation of the repository server for this transaction.
      - This should be set to V(false) if one of the configured repositories is using an untrusted or self-signed certificate.
    type: bool
    default: "yes"
    version_added: "2.13"
  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 O(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.7"
  install_repoquery:
    description:
      - This is effectively a no-op in DNF as it is not needed with DNF.
      - This option is deprecated and will be removed in ansible-core 2.20.
    type: bool
    default: "yes"
    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 dnf 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.
    type: bool
    default: "yes"
    version_added: "2.8"
  download_dir:
    description:
      - Specifies an alternate directory to store packages.
      - Has an effect only if O(download_only) is specified.
    type: str
    version_added: "2.8"
  allowerasing:
    description:
      - If V(true) it allows erasing of installed packages to resolve dependencies.
    required: false
    type: bool
    default: "no"
    version_added: "2.10"
  nobest:
    description:
      - This is the opposite of the O(best) option kept for backwards compatibility.
      - Since ansible-core 2.17 the default value is set by the operating system distribution.
    required: false
    type: bool
    version_added: "2.11"
  best:
    description:
      - When set to V(true), either use a package with the highest version available or fail.
      - When set to V(false), if the latest version cannot be installed go with the lower version.
      - Default is set by the operating system distribution.
    required: false
    type: bool
    version_added: "2.17"
  cacheonly:
    description:
      - Tells dnf to run entirely from system cache; does not download or update metadata.
    type: bool
    default: "no"
    version_added: "2.12"
extends_documentation_fragment:
- action_common_attributes
- action_common_attributes.flow
attributes:
    action:
        details: dnf has 2 action plugins that use it under the hood, M(ansible.builtin.dnf) 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 O(name) option.
  - Group removal doesn't work if the group was installed with Ansible because
    upstream dnf's API doesn't properly mark groups as installed, therefore upon
    removal the module is unable to detect that the group is installed
    U(https://bugzilla.redhat.com/show_bug.cgi?id=1620324).
  - While O(use_backend=yum) and the ability to call the action plugin as
    M(ansible.builtin.yum) are provided for syntax compatibility, the YUM
    backend was removed in ansible-core 2.17 because the required libraries are
    not available for any supported version of Python. If you rely on this
    functionality, use an older version of Ansible.
requirements:
  - python3-dnf
author:
  - Igor Gnatenko (@ignatenkobrain) <i.gnatenko.brain@gmail.com>
  - Cristian van Ee (@DJMuggs) <cristian at cvee.org>
  - Berend De Schouwer (@berenddeschouwer)
  - Adam Miller (@maxamillion) <admiller@redhat.com>
aR  
- name: Install the latest version of Apache
  ansible.builtin.dnf:
    name: httpd
    state: latest

- name: Install Apache >= 2.4
  ansible.builtin.dnf:
    name: httpd >= 2.4
    state: present

- name: Install the latest version of Apache and MariaDB
  ansible.builtin.dnf:
    name:
      - httpd
      - mariadb-server
    state: latest

- name: Remove the Apache package
  ansible.builtin.dnf:
    name: httpd
    state: absent

- name: Install the latest version of Apache from the testing repo
  ansible.builtin.dnf:
    name: httpd
    enablerepo: testing
    state: present

- name: Upgrade all packages
  ansible.builtin.dnf:
    name: "*"
    state: latest

- name: Update the webserver, depending on which is installed on the system. Do not install the other one
  ansible.builtin.dnf:
    name:
      - httpd
      - nginx
    state: latest
    update_only: yes

- name: Install the nginx rpm from a remote repo
  ansible.builtin.dnf:
    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.dnf:
    name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    state: present

- name: Install Package based upon the file it provides
  ansible.builtin.dnf:
    name: /usr/bin/cowsay
    state: present

- name: Install the 'Development tools' package group
  ansible.builtin.dnf:
    name: '@Development tools'
    state: present

- name: Autoremove unneeded packages installed as dependencies
  ansible.builtin.dnf:
    autoremove: yes

- name: Uninstall httpd but keep its dependencies
  ansible.builtin.dnf:
    name: httpd
    state: absent
    autoremove: no

- name: Install a modularity appstream with defined stream and profile
  ansible.builtin.dnf:
    name: '@postgresql:9.6/client'
    state: present

- name: Install a modularity appstream with defined stream
  ansible.builtin.dnf:
    name: '@postgresql:9.6'
    state: present

- name: Install a modularity appstream with defined profile
  ansible.builtin.dnf:
    name: '@postgresql/client'
    state: present
N)	to_nativeto_text)
fetch_file)AnsibleModule)get_best_parsable_locale)has_respawnedprobe_interpreters_for_modulerespawn_module)YumDnfyumdnf_argument_specc                       e Zd ZdZ fdZd Zd Zd ZddZd Z	d Z
d	 Zd
 Zd ZddZd Zd Zd Zd Zd Zd Z xZS )	DnfModulez4
    DNF Ansible module back-end implementation
    c                    t         t        |   |       | j                          d| _        t
        j                  j                  | _        y )Ndnf)	superr   __init___ensure_dnfpkg_mgr_namer   baseWITH_MODULESwith_modules)selfmodule	__class__s     C/home/dcms/DCMS/lib/python3.12/site-packages/ansible/modules/dnf.pyr   zDnfModule.__init__  s8    i'/!HH11    c                    t        d      t        |      v st        d      t        |      v rdj                  |      S |S )z
        For unhandled dnf.exceptions.Error scenarios, there are certain error
        messages we want to filter in an install scenario. Do that here.
        zno package matchedzNo match for argument:No package {0} available.)r   format)r   specerrors      r   _sanitize_dnf_error_msg_installz)DnfModule._sanitize_dnf_error_msg_install  s>     ()WU^;,-?.55d;;r   c                   |j                   |j                  t        |j                        |j                  |j
                  |j                  d} dj                  d	i ||d<   |d   |d<   |j                  dk(  rd|d<   |S d|d<   |S )
z3Return a dictionary of information for the package.)namearchepochreleaseversionrepoz){epoch}:{name}-{version}-{release}.{arch}envranevrar   	availableyumstate	installed )	r%   r&   strr'   r(   r)   repoidr    installtime)r   packageresults      r   _package_dictzDnfModule._package_dict  s    
 LLLL'NN$ MELLVvVw !/w!#!,F:  "-F:r   c           	     &   t        | j                        }|xt        j                  d<   t        j                  d<   |xt        j                  d<   t        j                  d<   	 dd ladd ladd ladd ladd ladd l	ad}|ry g d}t               st        |d	      }|rt        |       | j                  j                  d
j                  t         j"                  t         j$                  j'                  dd      |      g        y # t        $ r d}Y w xY w)NLC_ALLLC_MESSAGESLANGUAGELANGr   TF)z/usr/libexec/platform-pythonz/usr/bin/python3z/usr/bin/pythonr   zCould not import the dnf python module using {0} ({1}). Please install `python3-dnf` package or ensure you have specified the correct ansible_python_interpreter. (attempted {2})
 msgresults)r   r   osenvironr   	dnf.constdnf.exceptionsdnf.packagednf.subjectdnf.utilImportErrorr	   r
   r   	fail_jsonr    sys
executabler)   replace)r   localeHAS_DNFsystem_interpretersinterpreters        r   r   zDnfModule._ensure_dnf  s    )$++6;AA

8rzz-86<<

:F!3		!G 2 78KUSK{+ 	F (;(;D"(EGZ[ 	 	
)  	G	s   #D DDc                   |j                   }|rJt        j                  |t        j                        s| j                  j                  d|g        n||_        |j                          d|_        | |_	        | |_
        d|_        ||_        ||_        |j                  j                  |       | j                   r7t#        |j                         }|j%                  | j                          ||_        | j&                  rEt#        |j&                        }| j&                  |vr"|j)                  | j&                         ||_        | j*                  | j*                  |j                  d<   |j                  j-                  d      *| j                  j/                  d       d|j                  d<   d	D ]  }	|j1                  |	        | j2                  rd|_        | j6                  | j6                   |_        n| j8                  | j8                  |_        | j:                  r$d|_        | j>                  r| j>                  |_         | jB                  rd|_!        | jD                  |_#        | jH                  |_$        y)
zConfigure the dnf Base object.zcannot read configuration file)r?   	conf_filer@   r   TN
releaseverzUUnable to detect release version (use "releasever" option to specify release version)r=   )cachedirlogdir
persistdir)%confrA   accessR_OKr   rI   config_file_pathread
debuglevelgpgchecklocalpkg_gpgcheck	assumeyes	sslverifyinstallrootsubstitutionsupdate_from_etcexcludelistextenddisable_excludesappendrS   getwarnprepend_installrootskip_brokenstrictnobestbestdownload_onlydownloadonlydownload_dirdestdir	cacheonly
autoremoveclean_requirements_on_removeinstall_weak_deps)
r   r   rR   disable_gpg_checkra   r`   rW   	_excludes_disable_excludesopts
             r   _configure_basezDnfModule._configure_base   s/    yy 99Y0%%8I & 
 )2% 			  .-%6!6  # ' 	**;7 <<T\\*IT\\*$DL   $T%:%: ;$$,==!(()>)>?(9% ??&/3D|,!!,/7KKg
 02D|, 8 	*C$$S)	* DK ;;" KKDIYY"		DI $D  #00>>!DN -1OO) "&!7!7r   c                p   |j                          |j                  }|D ]+  }|s|j                  |      D ]  }|j                           - |D ]+  }|s|j                  |      D ]  }|j	                           - |j                  j                         D ]  }| j                  sd|_        d|_         y)z?Enable and disable repositories matching the provided patterns.FN)	read_all_reposreposget_matchingdisableenableiter_enabledrx   r]   repo_gpgcheck)r   r   disablerepo
enablerepor   repo_patternr*   s          r   _specify_repositorieszDnfModule._specify_repositoriesd  s    

 ( 	#L!..|< #DLLN#	# ' 	"L!..|< "DKKM"	"
 JJ++- 	+D%% %%*"	+r   c                   t         j                         }| j                  |||||       |j                          |j	                  t        | j                        t        | j                               |j                          | j                  |||       |j                          	 | j                  r	 |j                          |j%                  d       t'        |dd      }	t)        |	      rhi }
| j*                  r!|
j-                  dg       j/                  d	       | j0                  r!|
j-                  dg       j/                  d
       |
r |	di |
 |S g }
| j*                  rKdd	i}|
j/                   |j2                  j5                         j7                         j8                  di |       | j0                  rKdd
i}|
j/                   |j2                  j5                         j7                         j8                  di |       |
r|
|_        |S # t         j                  j                  $ rA}| j                  j                  dj!                  t#        |            g d       Y d}~d}~ww xY w# t         j                  j                  $ rA}| j                  j                  dj!                  t#        |            g d       Y d}~d}~ww xY w)z*Return a fully configured dnf Base object.z{0}   r?   r@   rcNauto)load_system_repoadd_security_filterstypesbugfixsecurityadvisory_type__eq)eqr0   )r   Baser|   setup_loggersinit_pluginssetdisable_pluginenable_pluginpre_configure_pluginsr   configure_pluginsupdate_cache
exceptions	RepoErrorr   rI   r    r   	fill_sackgetattrcallabler   
setdefaultrh   r   sackqueryupgradesfilter_update_security_filters)r   rR   rx   r   r   ra   r`   r   er   filterskeys               r   _basezDnfModule._basez  s_   xxzT9.?iX#d112C8J8J4KL""$""4jA 	  %%' NNFN3  't-CTJ()G{{""7B/66x@}}""7B/66zB$5W5  G{{*H5Btyy099;BBISIJ}}*J7Btyy099;BBISIJ07-E ~~// KK))!LL4 " *   ~~'' 	KK!!LL, "  	sB   &I1 3H I1 I.-6I)#I1 )I..I1 1K6K

Kc                X   |dk(  rd}|dv rP t        | j                  j                  j                         |             D cg c]  }| j	                  |       }}n|dv r?| j                  j
                  j                         D cg c]  }|j                  dd }}n`t        j                  j                  |      j                  | j                  j                        }|D cg c]  }| j	                  |       }}| j                  j                  d|       y	c c}w c c}w c c}w )
z'List package info based on the command.updatesr   )r/   r   r-   )r   repositoriesenabled)r2   stater=   r>   N)r   r   r   r   r6   r   r   idr   subjectSubjectget_best_queryr   	exit_json)r   commandr4   r@   r*   packagess         r   
list_itemszDnfModule.list_items  s    i G <<  Hwtyy~~';';'=wGIK ""7+KG K 11 !IIOO88:<  77Y7<G <
 {{**73BB499>>RHBJKwt))'2KGK"g6K
< Ls   DD"%D'c                   t         j                  j                  |      j                  | j                  j
                        j                         }t         j                  j                  |      rt         j                  j                  |      j                  | j                  j
                        j                         }|D ch c]  }|j                   c}|D ch c]  }|j                   c}z
   S t        |      S c c}w c c}w )Nr   )r   r   r   r   r   r   r/   utilis_glob_patternr-   r%   bool)r   pkginstalled_queryavailable_queryps        r   _is_installedzDnfModule._is_installed  s    ++--c2AAtyy~~AV``b88##C(!kk11#6EE499>>EZddfO!01A1_4UQVV4UU  (( 24Us   DDc                   	 t        |t        j                  j                        rtt	        | j
                  j                  j                         j                         j                  |j                  |j                              d   }|j                  |      S t        j                  j                  |      j                  | j
                  j                        j!                         }| j
                  j                  j                         j                         j                  |d   j                        }t	        t#        d |D                    D ]R  }t	        |j                  |            d   }	 t	        |j                  |            d   }|j                  |      sR y y	# t$        $ r Y aw xY w# t$        $ r Y y	w xY w)
N)r%   r&   r   r   )r%   c              3  4   K   | ]  }|j                     y wNr&   ).0r   s     r   	<genexpr>z8DnfModule._is_newer_version_installed.<locals>.<genexpr>  s     &A!qvv&As   r   TF)
isinstancer   r4   Packagesortedr   r   r   r/   r   r%   r&   evr_gtr   r   r   r-   r   
IndexError)r   pkg_specr/   r-   r&   installed_pkgavailable_pkgs          r   _is_newer_version_installedz%DnfModule._is_newer_version_installed  s|   	(CKK$7$78"499>>#7#7#9#C#C#E#L#LRZR_R_fnfsfs#L#tuvxy	 ''11KK//9HHdiinnH]ggi	 IINN002<<>EE9UV<K\K\E]	"3&Ay&A#AB $D$*9+;+;+;+F$G$KM!(.y/?/?T/?/J(KB(O %++M:#$ 	 & ! !
  		sI   BF: CF: 7F+F: 'F: )F: +	F74F: 6F77F: :	GGc           	        | j                  |      }| j                  |      }d}	 |r| j                  r|rZ|r| j                  j	                  |       n| j                  j                  || j                  j                  j                         n| j                  j                  || j                  j                  j                         n]n\|r|r| j                  j	                  |       n<n;| j                  j                  || j                  j                  j                         d|dddS # t        j                  j                  $ rb}dj                  |      }| j                  j                  j                  r'd|dj                  |t        |      f      dg dcY d}~S Y d}~d}~wt        j                  j                  $ r;}dd	j                  |      dj                  |t        |      f      dg dcY d}~S d}~wt        j                  j                  $ r;}dd
j                  |      dj                  |t        |      f      dg dcY d}~S d}~ww xY w)zMark the package for install.r=   rm   r   T r   )failedr?   failurer   r@   Nz(Depsolve Error occurred for package {0}.z'Unknown Error occurred for package {0}.Fr   )r   r?   r   r   )r   r   allow_downgrader   upgradeinstallrW   rm   r   r   MarkingErrorr    joinr   DepsolveErrorError)r   r   r   is_newer_version_installedis_installedr?   r   s          r   _mark_package_installzDnfModule._mark_package_install  s   %)%E%Eh%O"))(3:	)''
 ' !II--h7 II--htyy~~?T?T-U		))(499>>;P;P)QII%%h/		!!(499>>3H3H!I8  !DD7 ~~** 		-44X>Cyy~~$$""xx9Q<(@A!  % ~~++ 	AHHR88Xy|$<=  ~~## 	@GGQ88Xy|$<= 	sC   DD0 0IAF*I* I
0H :I  I 0IIIc                   g g g g f\  }}}}d}| j                   D ]  }d|v r(t        | j                  |      }|j                  |       0|j	                  d      r|j                  |       S|j                  d      r| j                  j                  j                         j                  ||      j                         j                         }|r|j                  |d   j                         | j                  r|j                  |       |j                  d      sd|v r|s| j                  j                          d}|d	d  j                         }| j                   rF| j"                  j%                  |      }	|	d   r|j                  |       z|j                  |       |j                  |       |j                  |        ||||fS )
NFz://z.rpm/)providesfiler   @Tr   )namesr   r   rh   endswith
startswithr   r   r   r   r/   runr%   update_only
read_compsstripr   module_base_get_modules)
r   	pkg_specs	grp_specsmodule_specs	filenamesalready_loaded_compsr%   r/   grp_env_mdl_candidatemdls
             r   _parse_spec_group_filez DnfModule._parse_spec_group_file'  s   8:BB5	9lI$JJ 	'D}!$++t4  &v&  &% IINN002994d9S]]_cce	$$Yq\%6%67))$$T*%#++II((*+/((,QR(8%$$**778MNC1v$++,AB!(()>?$$%:;  &=	'> )\9<<r   c           	         g }|D ]  }| j                  t        |t        j                  j                        r| j                  |      d   n|      r]	 t        |t        j                  j                        r| j                  j                  |       n| j                  j                  |       |j                  |        |S # t        $ rA}| j                  j                  dj                  t        |            g d       Y d }~d }~ww xY w)Nr,   z4Error occurred attempting update_only operation: {0}r   r   )r   r   r   r4   r   r6   r   package_upgrader   	Exceptionr   rI   r    r   rh   )r   pkgsnot_installedr   r   s        r   _update_onlyzDnfModule._update_onlyL  s     	*C!!8B3H[H[8\D&&s+G4be
!#s{{':':;		11#6		))#. $$S)!	*$  ! KK))RYYZcdeZfg " *  s   AC	D6DDc                   	 | j                   j                  |      }| j                  r| j                  |       y |D ][  }| j	                  |      r| j
                  s!| j                   j                  || j                   j                  j                         ] y # t        $ r@}| j                  j                  dj                  t        |            g d       Y d }~y d }~ww xY w)Nr   z3Error occurred attempting remote rpm operation: {0}r   r   )r   add_remote_rpmsr   r   r   r   package_installrW   rm   r   r   rI   r    r   )r   r   r   r   r   s        r   _install_remote_rpmszDnfModule._install_remote_rpmsb  s    	99,,Y7D!!$' UC <<SA$J^J^		11#diinn>S>S1TU  	KK!!IPPQZ[\Q]^ "  	s"   8B "B =B 	C%%6C  C%c                   | j                   r||j                         }| j                  j                  |      \  }}| j                  j
                  j                  |j                        }|r|j                  r|j                  |v ryyyy)NTF)	r   r   r   r   r   _moduleContainergetEnabledStreamr%   stream)r   module_specmodule_listnsvenabled_streamss        r   _is_module_installedzDnfModule._is_module_installedr  st    %++-K#//<<[IK"ii88II#((SO::zz_4#$r   c           
     x#   ddg dd}dg g dd}| j                   s| j                  rg | _         d| _        | j                   dgk(  r,| j                  d	k(  r	 | j                  j	                          n| j                         \  }}}}|D cg c]  }|j                          }}|D 	cg c]  }	|	j                          }}	g }
g }d |D        D ]  }| j                  j                  j                  |      }|r|
j                  |j                         F| j                  j                  j!                  |      }|r|j                  |j                         | j                  j                  dj#                  |      g         | j                  dv rt| j%                  |       |D ]%  }|d   j                  dj#                  |             ' |r| j&                  rt|D ]o  }	 | j)                  |      s#|d   j                  dj#                  |             | j*                  j-                  |g       | j*                  j/                  |g       q |
D ]  }	 | j                  j7                  |t
        j8                  j:                        }|dk(  r$|d   j                  dj#                  |             n#|d   j                  dj#                  |              |D ]7  }	 | j                  j?                  |t
        j8                  j:                         9 |r;| j&                  s/| j                  j                  dj#                  |d         g        | j@                  r1| jC                  |      }|D ]  }|d   j                  d|z          n|D ]r  }| jE                  |      }|d   r=|d   r|dxx   |d   z  cc<   |d   j                  | jG                  ||d                V|d   s\|d   j                  |d          t n'| j                  d	k(  r| j%                  |       |D ]%  }|d   j                  dj#                  |             ' |rd| j&                  rX|D ]S  }	 | j)                  |      r#|d   j                  dj#                  |             | j*                  jI                  |g       U |
D ]B  }	 	 | j                  jK                  |       |d   j                  dj#                  |             D |D ]  }	 	 | j                  jO                  |       ! | j@                  r1| jC                  |      }|D ]  }|d   j                  d|z          n|D ]t  }| jE                  |d      }|d   r=|d   r|dxx   |d   z  cc<   |d   j                  | jG                  ||d                X|d   s^|d   j                  |d          v nS|r| j                  j                  d g        |r| j&                  r|D ]  }	 | j)                  |      r#|d   j                  d!j#                  |             | j*                  jQ                  |g       | j*                  jS                  |g       | j*                  jU                  |g        |
D ]  }	 | j                  jW                  |         |D ]  }	 | j                  jY                  |         |D ]  }	 | j                  jQ                  |         d| _/        | j                  r| j                  j                          	 | j                  ja                  | j^                  #      sH|d   r!d$|d<    | j                  j                  d0i | d%|d<    | j                  jb                  d0i | y d|d&<   | jd                  rd'}nd(}| j                  jf                  jh                  D ]&  }|d   j                  d)j#                  ||             ( | j                  jf                  jj                  D ]%  }|d   j                  d*j#                  |             ' |d   r!d$|d<    | j                  j                  d0i | | j                  jl                  r!d+|d<    | j                  jb                  d0i | 	 | jd                  r| jn                  r| j                  jp                  jr                  rt
        jt                  jw                  | j                  jp                  jr                         | j                  jp                  jr                  | j                  jx                  j{                         _>        | j                  j                  | j                  jf                  jh                         | j                  s| j                  jf                  jh                  D ]|  }d}| j                  j                  |      \  }}|dk(  r)|dk(  r	 | j                  j                  |       nd}|sPd-j#                  ||      }| j                  j                  |       ~ | jd                  r | j                  jb                  d0i | ns| j                  j                         }|W| j                  j                  j                  |g      d   }|j                  r"|d   j                  |j                                |d   r!d$|d<    | j                  j                  d0i |  | j                  jb                  d0i | y # t
        j                  j                  $ r,}d
|d<    | j                  j                  d0i | Y d }~7d }~ww xY wc c}w c c}	w # t
        j                  j0                  $ r9}|d   j                  dj3                  |t5        |      f             Y d }~	d }~ww xY w# t
        j                  j                  $ r;}dj#                  |      |d<    | j                  j                  d0i | Y d }~	d }~wt
        j                  j<                  $ r9}|d   j                  dj3                  |t5        |      f             Y d }~
%d }~ww xY w# t
        j                  j                  $ r;}dj#                  |      |d<    | j                  j                  d0i | Y d }~	d }~wt
        j                  j<                  $ r9}|d   j                  dj3                  |t5        |      f             Y d }~
Ld }~ww xY w# t
        j                  j0                  $ r9}|d   j                  dj3                  |t5        |      f             Y d }~	d }~ww xY w# t
        j                  jL                  $ r | j@                  s| j                  j7                  |t
        j8                  j:                        }|dk(  r$|d   j                  dj#                  |             n#|d   j                  dj#                  |             Y 	6w xY w# t
        j                  j<                  $ r9}|d   j                  dj3                  |t5        |      f             Y d }~	d }~ww xY w# t
        j                  jL                  $ r8 | j                  j?                  |t
        j8                  j:                         Y 	w xY w# t
        j                  j                  $ r}dj#                  |      |d<   Y d }~
d }~wt
        j                  j<                  $ r9}|d   j                  dj3                  |t5        |      f             Y d }~
rd }~ww xY w# t
        j                  j0                  $ r9}|d   j                  dj3                  |t5        |      f             Y d }~	d }~ww xY w# t
        j                  jL                  $ r Y 	Zw xY w# t
        j                  jL                  $ r Y 	[w xY w# t
        j                  jZ                  $ r.}|d   j                  |j\                   d"|        Y d }~	d }~ww xY w# t
        j                  j                  $ rD}d,j#                  t5        |            |d<    | j                  j                  d0i | Y d }~/d }~ww xY w# t
        j                  j<                  $ r}d}Y d }~d }~ww xY w# t
        j                  j                  $ rC}d.j#                  t5        |            |d<    | j                  j                  d0i | Y d }~y d }~wt
        j                  j<                  $ rC}d/j#                  t5        |            |d<    | j                  j                  d0i | Y d }~y d }~ww xY w)1Nr=   Fr   r?   changedr@   r   r   )r?   failuresr@   r   absent*latestz:Depsolve Error occurred attempting to upgrade all packagesr?   c              3  <   K   | ]  }|j                           y wr   )r   )r   gs     r   r   z#DnfModule.ensure.<locals>.<genexpr>  s     >Qqwwy>s   zNo group {0} available.r>   )r/   presentr@   zInstalled {0}zModule {0} installed.r  r   zGroup {0} already installed.zGroup {0} installed.z8Depsolve Error occurred attempting to install group: {0}z>Depsolve Error occurred attempting to install environment: {0}z@Packages providing %s not installed due to update_only specifiedr   r   zModule {0} upgraded.zGroup {0} upgraded.T)r   z3Cannot remove paths -- please specify package name.zModule {0} removed.z: )allow_erasingz0Failed to install some of the specified packageszNothing to dor  
Downloaded	Installedz{0}: {1}zRemoved: {0}z@Check mode: No changes made, but would have if not in check modez Failed to download packages: {0}z-Failed to validate GPG signature for {0}: {1}zDepsolve Error occurred: {0}zUnknown Error occurred: {0}r0   )Ir   ru   r   r   upgrade_allr   r   r   r   rI   r   r   compsgroup_by_patternrh   r   environment_by_patternr    r  r   r  r   r   r   MarkingErrorsr   r   group_installconstGROUP_PACKAGE_TYPESr   environment_installr   r   r   r#   r   group_upgrade
CompsErrorenvironment_upgraderemover   resetgroup_removeenvironment_remover   valueallowerasingresolver   rp   transactioninstall_set
remove_set
check_moderr   rW   rs   r   
ensure_dirr   allpkgdirdownload_packagesDownloadErrorrx   _sig_check_pkg_get_key_for_packagedo_transactionhistoryoldreturn_codeoutput)r   responsefailure_responser   r   group_specsr   r   r   fgroupsenvironments
group_specgroupenvironmentfilenamer   group_pkg_count_installedr   r!   r   install_resultinstall_actionr4   failgpgresgpgerrr?   tidr,  s                                 r   ensurezDnfModule.ensure  s-    	
 	
 zzdooDJ!DJ::#4::#9:		%%'
 ?C>Y>Y>[;I{L),56q6I6,56q6I6FL>+> 
		88DMM%((+"&))//"H"H"TK"$++KNN;-- 9 @ @ L$& .  zz55)))4 ) QHY'../E/Eh/OPQ  D$5$5". bb#'#<#<V#D ( 3 : :;R;Y;YZ`;a b ,,44fX> ,,33VH=b $ ]E]48II4K4KESVS\S\SpSp4q149$Y/667U7\7\]b7cd$Y/667M7T7TUZ7[\]  $0 cKc		55k399C`C`ac  (9(9KK))5<<\!_M " *  ##$($5$5i$@M - ~ +223ux|3|}~ %. R)-)C)CH)M)(3-e4 0 7>%;P P 7,Z8??@d@demo}  H  pI  AJ  K-e4 ( 3 : :>%;P QR x')))4 ) QHY'../E/Eh/OPQ  D$5$5". bb#88@ ( 3 : :;Q;X;XY_;` a ,,44fX>	b $ ]E]
e II33E:$Y/667L7S7STY7Z[	]  $0 
cK	cf II99+F
c ##$($5$5i$@M - ~ +223ux|3|}~ %. R)-)C)CHVZ)C)[)(3-e4 0 7>%;P P 7,Z8??@d@demo}  H  pI  AJ  K-e4 ( 3 : :>%;P QR KK))Q " *   D$5$5". bb#88@ ( 3 : :;P;W;WX^;_ ` ,,33VH= ,,44fX> ,,22F8<b $ E		..u5 $0 K		44[A !* MHM		((2M %)!??II((*X	6 99$$43D3D$E#J/.`$U+)DKK))=,<="1%%%11&*# %%%1N%0N#yy44@@ [GY'..z/@/@QX/YZ[#yy44?? OGY'..~/D/DW/MNO $J/.`$U+)DKK))=,<=;;))&hHUO)DKK))5H5>))d.?.?DIINNDZDZ++DIINN,B,BC7;yy~~7M7M		++-4II//		0E0E0Q0QR --#'99#8#8#D#D 7$)-)A)A')J!Q;$#q[, $		 > >w G $(D"Q"X"XY`bh"iC KK11#67" %% *DKK))5H5))224C&*ii&7&7&;&;SE&B1&E&22,Z8??@R@R@TU#J/.`$U+)DKK))=,<=%%%11m >>// :*f '%%%9(899: 76>  #~~;; b,Z8??&R[\]R^I_@`aab >>77 B2l2s2sty2z(/---A0@AA>>// ] )4;;CHHeYWX\EZ<[\\	] >>77 B2r2y2y  {F  3G(/---A0@AA>>// c(4;;CHHkS\]^S_E`<abbcN  #~~;; b,Z8??&R[\]R^I_@`aab  #~~88 e#'#3#3<@II<S<STY[^[d[d[x[x<y 9#<#A$,Y$7$>$>?]?d?dej?k$l$,Y$7$>$>?U?\?\]b?c$de >>// ](4;;CHHeYWX\EZ<[\\]  #~~88 f II99+syyGdGdef >>77 G2r2y2y  {F  3G(/>>// c(4;;CHHkS\]^S_E`<abbcF  #~~;; b,Z8??&R[\]R^I_@`aab >>44  >>44  >>66 M +22aggYb
3KLLMl ~~33 >.P.W.WXabcXd.e$U+)DKK))=,<==> $'>>#7#7 ,'+,0 ~~++ 	6&D&K&KIVWL&YU#!DKK!!5$45~~## 	6&C&J&J9UV<&XU#!DKK!!5$45	6s  l! 
m-'m2"A,m7B o4q?&At.?>vzB};8$A@/A-AC; DAC; "C5AA* AAC; 2ACAC; DAC; !m*>!m%%m*7o.ooq<-0p## q<.q77q<?t+0s t+2.t&&t+.v.u??vB)x40x73x44x77z.zzA{%!{(${%%{((}8| }8?.}33}8;.5458A@@A@@AA'@9#AA"A"AA'A*ACB9ACC AC; CACCAC; CAC8C+AC3C-AC; C3AC8C8AC; C;AF9D9AEE AF9E69AF4F4AF9c                   | j                   r| j                  s| j                  sv| j                  | j                  | j
                  | j                  | j                  | j                  | j                        | _
        | j                  j                  ddg d       | j                  d| _        | j                  rs| j                  | j                  | j
                  | j                  | j                  | j                  | j                        | _
        | j                  | j                         y | j                  s;t         j"                  j%                         s| j                  j'                  dg        | j                  | j                  | j
                  | j                  | j                  | j                  | j                        | _
        | j(                  r8t         j                  j*                  j-                  | j                        | _        	 | j/                          | j                  j1                          y # | j                  j1                          w xY w)NzCache updatedFr   r  r/   z/This command has to be run under the root user.r>   )r   r   re   r   rR   rx   r   r   ra   r`   r   r   r   r   r   rp   r   r   	am_i_rootrI   r   r   
ModuleBaserM  close)r   s    r   r   zDnfModule.run  s   TZZ		

 6 68H8H!1!14>>DI KK!!#	 "  ::$DJ99

 6 68H8H!1!14>>DI OODII& %%chh.@.@.B%%I &  

 6 68H8H!1!14>>DI
   #&::#9#9#D#DTYY#O "		!		!s   H; ;I)r   T)F)__name__
__module____qualname____doc__r   r#   r6   r   r|   r   r   r   r   r   r   r   r   r  r  rM  r   __classcell__)r   s   @r   r   r     sg    24(
Tb8H+,3j7.)(AEF#=J, "w6r	+"r   r   c                 :   t        dg d      t        d   d<   t        d
i t        } t        |       }	 |j	                          y # t
        j                  j                  $ r7}| j                  dj                  t        |            dg d	       Y d }~y d }~ww xY w)Nr   )r   r   yumyum4dnf4dnf5)defaultchoicesargument_specuse_backendz#Failed to synchronize repodata: {0}r   F)r?   r   r@   r  r0   )dictr   r   r   r   r   r   r   rI   r    r   )r   module_implementationdes      r   mainrc    s     <@  YG  <H)-8 
F &f-
!!#>>## 
5<<Yr]K	 	 	
 	

s   A B#-BB__main__)
__future__r   DOCUMENTATIONEXAMPLESrA   rJ   +ansible.module_utils.common.text.convertersr   r   ansible.module_utils.urlsr   ansible.module_utils.basicr   "ansible.module_utils.common.localer   #ansible.module_utils.common.respawnr	   r
   r   ansible.module_utils.yumdnfr   r   r   r   rc  rR  r0   r   r   <module>rn     sh    #iV	Vp 
 
 J 0 4 G l l D E" E"P
< zF r   