概述
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'