o nnh+l@sddlmZdZdZdZddlZddlZddlmZddl m Z ddl m Z m Z mZdd lmZmZdad d Zd d ZddZddZGdddeZddZedkrYedSdS)) annotationsaz$ module: dnf5 author: Ansible Core Team description: - Installs, upgrade, removes, and lists packages and groups with the I(dnf5) package manager. - "WARNING: The I(dnf5) package manager is still under development and not all features that the existing M(ansible.builtin.dnf) module provides are implemented in M(ansible.builtin.dnf5), please consult specific options for more information." short_description: Manages packages with the I(dnf5) package manager options: 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 V(autoremove) option is enabled for this module, then V(absent) is inferred. choices: ['absent', 'present', 'installed', 'removed', 'latest'] type: str 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 ",". type: list elements: str default: [] 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 ",". 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) is V(present) or V(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. default: "/" type: str releasever: description: - Specifies an alternative release from which all packages will be installed. 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) is V(absent) type: bool default: "no" exclude: description: - Package name(s) to exclude when state=present, or latest. This can be a list or a comma separated string. 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 --skip-broken option. type: bool default: "no" update_cache: description: - Force dnf to check if cache is out of date and redownload if needed. Has an effect only if O(state) is V(present) or V(latest). type: bool default: "no" aliases: [ expire-cache ] update_only: description: - When using latest, only update installed packages. Do not install packages. - Has an effect only if O(state) is V(latest) default: "no" type: bool 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" 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 enable_plugin: description: - This is currently a no-op as dnf5 itself does not implement this feature. - I(Plugin) name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction. type: list elements: str default: [] disable_plugin: description: - This is currently a no-op as dnf5 itself does not implement this feature. - I(Plugin) name to disable for the install/update operation. The disabled plugins will not persist beyond the transaction. 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 [main] in dnf.conf. - If set to V(repoid), disable excludes defined for given repo id. type: str validate_certs: description: - This is effectively a no-op in the dnf5 module as dnf5 itself handles downloading a https url as the source of the rpm, but is an accepted parameter for feature parity/compatibility with the M(ansible.builtin.dnf) module. type: bool default: "yes" 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" 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" 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" download_only: description: - Only download the packages, do not install them. default: "no" type: bool lock_timeout: description: - This is currently a no-op as dnf5 does not provide an option to configure it. - Amount of time to wait for the dnf lockfile to be freed. required: false default: 30 type: int install_weak_deps: description: - Will also install all packages linked by a weak dependency relation. type: bool default: "yes" download_dir: description: - Specifies an alternate directory to store packages. - Has an effect only if O(download_only) is specified. type: str allowerasing: description: - If V(true) it allows erasing of installed packages to resolve dependencies. required: false type: bool default: "no" 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 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" extends_documentation_fragment: - action_common_attributes - action_common_attributes.flow attributes: action: details: dnf5 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 requirements: - "python3" - "python3-libdnf5" version_added: 2.15 a - name: Install the latest version of Apache ansible.builtin.dnf5: name: httpd state: latest - name: Install Apache >= 2.4 ansible.builtin.dnf5: name: httpd >= 2.4 state: present - name: Install the latest version of Apache and MariaDB ansible.builtin.dnf5: name: - httpd - mariadb-server state: latest - name: Remove the Apache package ansible.builtin.dnf5: name: httpd state: absent - name: Install the latest version of Apache from the testing repo ansible.builtin.dnf5: name: httpd enablerepo: testing state: present - name: Upgrade all packages ansible.builtin.dnf5: name: "*" state: latest - name: Update the webserver, depending on which is installed on the system. Do not install the other one ansible.builtin.dnf5: name: - httpd - nginx state: latest update_only: yes - name: Install the nginx rpm from a remote repo ansible.builtin.dnf5: 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.dnf5: 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.dnf5: name: /usr/bin/cowsay state: present - name: Install the 'Development tools' package group ansible.builtin.dnf5: name: '@Development tools' state: present - name: Autoremove unneeded packages installed as dependencies ansible.builtin.dnf5: autoremove: yes - name: Uninstall httpd but keep its dependencies ansible.builtin.dnf5: name: httpd state: absent autoremove: no a msg: description: Additional information about the result returned: always type: str sample: "Nothing to do" results: description: A list of the dnf transaction results returned: success type: list sample: ["Installed: lsof-4.94.0-4.fc37.x86_64"] failures: description: A list of the dnf transaction failures returned: failure type: list sample: ["Argument 'lsof' matches only excluded packages."] rc: description: For compatibility, 0 for success, 1 for failure returned: always type: int sample: 0 N) AnsibleModule)get_best_parsable_locale) has_respawnedprobe_interpreters_for_modulerespawn_module)YumDnfyumdnf_argument_speccstj}z |d|dWnty d|_d|_Ynwtj |}| | ||d\}}t dt fdd|Drctj |}|| ||ddd|Ddd|D S|S)NTFz*[?c3s|] }t|@VqdSN)set).0char glob_patterns?/usr/local/lib/python3.10/dist-packages/ansible/modules/dnf5.py ~szis_installed..cSsh|]}|qSr)get_name)r prrr zis_installed..)libdnf5baseResolveSpecSettingsset_group_with_nameset_with_binariesAttributeErrorgroup_with_name with_binariesrpm PackageQueryfilter_installedresolve_pkg_specr anyfilter_available)rspecsettingsinstalled_querymatchnevraavailable_queryrrr is_installedfs&      r+c Csbd|vr|dd}|dr|dd}z tttjj|}Wn tt fy/YdSw| }|s8dStj |}| | |g|zt|d}Wn ty`YdSwtj |}| |g||g|}|r||g|}|r||g|zt|d} Wn tyYdSwtj|| dkS)N/z.rpmF)splitendswithnextiterrrNevraparse RuntimeError StopIteration get_versionr r! filter_namerfilter_latest_evrlist IndexErrorfilter_version get_releasefilter_release get_epoch filter_epoch rpmvercmpget_evr) rr% spec_nevra spec_version installedinstalled_packagetarget spec_release spec_epochtarget_packagerrris_newer_version_installedsJ         rLc CsL||||t|||||r"dd Sdd S)NrF available) r)envranamearchepochreleaseversionrepoyumstate) get_nevrarget_archstrr@r>r8 get_repo_idr+)packagerrrpackage_to_dicts   r[ccs,tj|}|||EdHdSr )rrr r!filter_unneeded)rqueryrrrget_unneeded_pkgss  r^cs,eZdZfddZddZddZZS) Dnf5Modulecs"tt|||d|_dS)Ndnf5)superr___init__ _ensure_dnf pkg_mgr_name)selfmodule __class__rrrbs zDnf5Module.__init__cCst|j}|tjd<tjd<|tjd<tjd<d}zddlaWn ty,d}Ynw|r1dSgd}tsCt|d }|rCt||jj d t j t j d d |gd dS)NLC_ALL LC_MESSAGESLANGUAGELANGTrF)z/usr/libexec/platform-pythonz/usr/bin/python3z/usr/bin/python2z/usr/bin/pythonrzCould not import the libdnf5 python module using {0} ({1}). Please install python3-libdnf5 package or ensure you have specified the correct ansible_python_interpreter. (attempted {2}) )msgfailures)rrfosenvironr ImportErrorrrr fail_jsonformatsys executablerSreplace)relocalehas_dnfsystem_interpreters interpreterrrrrcs.     zDnf5Module._ensure_dnfc stjjdkr|jjdgdd|js$|js$tdkr$|jjdgdd|j s*|j r3|jjdgddt j }|}|jrC|j|_z|Wntyh}z|jjt||jgddWYd}~nd}~ww|jdury|}|d |j|jr|j|_|jr|jd krd |_|j|_|j|_|jdur|j |_n |jdur|j|_|j|_|j |_|j |_ |j!|_!|j"|_#|j$|_$d |_%|j&rd nd |_&|j'r|j'|_(|)|*}t j+,}||-t j+j.j/t j+0|d}|1||j2r)t j34|}|5t j3j6j7|D]} | 8} tj9:| r't j3;|| } | } | ?t j34|}|j@rN|A|j@t jBjC|D]} | DqF|jEre|A|jEt jBjC|D]} | Fq]z| GWntHyz| Id Ynw|j2r|jJs|js|jjKddgdd|jr|j} | dkrd} | dvrt jLM|}tN|dO| dd|D}n1| dvrt j34|}|Pd dd|D}nt j Q}t jLM|}|R| |d dd|D}|jjKd|ddt j S}z |Td |UdWntHyd |_Vd|_WYnw|jXs|jYrCt jZ[|}g}|jXr0|\d|jYr9|\d|5||]|t j ^|}g}|jJd gkr^|j_dkr^|`|n|j_d vr|j_dk}|jJD]:}ta||r|jbr~|c||qltd||r|r|e||ql|jfr|\d!O|ql|c||qlnF|j_d"vr|jJD]*}z |g||Wqty}z|jjt|gddWYd}~qd}~ww|j"rth|D] }|i||q|j|jkz|lWnty}z|jjt|gddWYd}~nd}~wwmrcg}nD]%}|ot j jpkrA|j_d vrA|\d#O|qq$|\|rq$mt j js@dkrXd$}nd%}|jj||ddd&d'd&d&d'd(}ttu}uD]$}|jr~d)}n t j jvw|x}|\d*O|-|||yzqud}|jj{r|rd+}nF||js}d,~t j jjkr|jjd-Od.gddnt j jjkr|jjd%fd/dDdd|s|sd0}|jjK|||dd1dS)2Nz"The dnf5 module requires Python 3.r/)rorprcrz/This command has to be run under the root user.zHenable_plugin and disable_plugin options are not yet implemented in DNF5)ro conf_filerpr~ releaseverall*Tnonezdnf5.logz Cache updatedF)rochangedresultsr~updatesupgrades>rrMrFz filter_{}cSg|]}t|qSrr[r rZrrr orz"Dnf5Module.run..>repos repositoriescSsg|] }|ddqS)enabled)repoidstate)get_id)r rTrrrrsscSrrrrrrrrxrrn)rorr~bugfixsecuritylatest>rpresentrFz@Packages providing {} not installed due to update_only specified>absentremovedzNo package {} available.zDepsolve Error occurredz0Failed to install some of the specified packages InstalledRemoved)InstallRemoveReplaceUpgradeReplaced Downloaded{}: {}z@Check mode: No changes made, but would have if not in check modezansible dnf5 modulez%Failed to validate GPG signatures: {},csg|] }d|qS)r)rutransaction_result_to_string)r logresult transactionrrrsz Nothing to do)rrror~)rv version_infomajorrfrtr; download_onlyrqgeteuid enable_plugindisable_pluginrrBase get_configrconfig_file_path load_configr6rXrget_varsr exclude excludepkgsdisable_excludes skip_brokennobestbestinstall_weak_depsdisable_gpg_checkgpgchecklocalpkg_gpgcheck sslverify autoremoveclean_requirements_on_remove installrootuse_host_config cacheonly download_dirdestdirsetup get_loggerlogger GlobalLoggergetLogger Level_DEBUGcreate_file_logger add_logger update_cacherT RepoQuery filter_typeRepoType_AVAILABLE get_cachedirpathexists RepoCachewrite_attributeATTRIBUTE_EXPIRED get_repo_sack&create_repos_from_system_configuration disablerepo filter_idcommonQueryCmp_IGLOBdisable enablerepoenable load_reposrupdate_and_load_enabled_reposnames exit_jsonrr getattrrufilter_enabledrr"GoalJobSettingsrrrrrradvisory AdvisoryQueryappendset_advisory_filterGoalradd_rpm_upgraderLallow_downgrade add_installr+ add_upgrade update_only add_remover^add_rpm_removeset_allow_erasing allowerasingresolve get_problemsget_resolve_logs get_problemGoalProblem_NOT_FOUNDget_spec to_stringGoalProblem_SOLVER_ERRORboolget_transaction_packagesr!transaction_item_action_to_string get_action get_packagerV check_modedownloadset_descriptionrun Transaction$TransactionRunResult_ERROR_GPG_CHECKjoinget_gpg_signature_problemsTransactionRunResult_SUCCESSget_transaction_problems)rerconfe variables log_router global_loggerr repo_queryrTrepo_dir repo_cachesackcommandr]rresolve_spec_settingsr&advisory_querytypesgoalupgrader%pkgrp log_eventroactions_compat_mapractionrrrrs                                            $   "    &    zDnf5Module.run)__name__ __module__ __qualname__rbrcr __classcell__rrrgrr_s )r_cCsttditdS)Nr)r_rr rrrrrmainsr$__main__) __future__r DOCUMENTATIONEXAMPLESRETURNrqrvansible.module_utils.basicr"ansible.module_utils.common.localer#ansible.module_utils.common.respawnrrransible.module_utils.yumdnfrr rr+rLr[r^r_r$r rrrrs. tI  $,,