概述
Installs, upgrade, removes, and lists packages and groups with the `dnf’ package manager
通過dnf管理數據包,比如安裝、更新、卸載和查看數據包
常用模塊
name
: A package name or package specifier with version, like `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 a rpm file.To operate on several packages this can accept a comma separated string of packages or a list of packages.
(Aliases: pkg)
指定需要安裝的數據包名稱,星號代表所有數據包
state
:Whether to install (present',
latest’), or remove (absent') a package.Default is
None’, however in effect the default action is present' unless the
autoremove’ option is enabled for this module, then `absent’ is inferred.
(Choices: absent, present, installed, removed, latest)[Default: (null)]
指定軟件包的狀態,installed、present和latest代表安裝,remove和absent代表刪除
disable_gpg_check
:Whether to disable the GPG checking of signatures of packages being installed. Has an effect only if state is present' or
latest’.
[Default: no]
type: bool
用於禁用對 rpm 包的公鑰 gpg 驗證
enablerepo
: `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 “,”.
[Default: (null)]
指定安裝軟件包時臨時啓用的 yum 源
disablerepo
: `Repoid’ of repositories to disable for the install/update operation. These repos will not persistbeyond the transaction. When specifying multiple repos, separate them with a “,”.
指定安裝軟件包時臨時禁用的 yum 源
示例
案例1:安裝最新版本的apache
- name: install the latest version of Apache
dnf:
name: httpd
state: latest
[root@control ~]# ansible node1 -m dnf -a 'name=httpd state=latest'
案例2:安裝最新版本的apache和mariadb
- name: install the latest version of Apache and MariaDB
dnf:
name:
- httpd
- mariadb-server
state: latest
[root@control ~]# ansible node1 -m dnf -a 'name=httpd,mariadb-server state=latest'
案例3:卸載apache
- name: remove the Apache package
dnf:
name: httpd
state: absent
[root@control ~]# ansible node1 -m dnf -a 'name=httpd state=absent'
案例4:使用testing源安裝apache
- name: install the latest version of Apache from the testing repo
dnf:
name: httpd
enablerepo: testing
state: present
[root@control ~]# ansible node1 -m dnf -a 'name=httpd state=latest enablerepo=testing'
案例5:更新所有軟件
- name: upgrade all packages
dnf:
name: "*"
state: latest
[root@control ~]# ansible node1 -m dnf -a 'name="*" state=latest'
案例6:根據遠端rpm包安裝軟件
- name: install the nginx rpm from a remote repo
dnf:
name: 'http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm'
state: present
[root@control ~]# ansible node1 -m dnf -a 'name="http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm" state=present'
案例7:根據本地rpm包安裝軟件
- name: install nginx rpm from a local file
dnf:
name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present
[root@control ~]# ansible node1 -m dnf -a 'name=" /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm" state=present'
案例8:安裝Development tool軟件集
- name: install the 'Development tools' package group
dnf:
name: '@Development tools'
state: present
[root@control ~]# ansible node1 -m dnf -a 'name=" @Development tools" state=latest'