用途: 包管理器,通过包管理器安装软件
[admin@node1 tasks]$ ansible-doc -s package
- name: Generic OS package manager
package:
name: # (required) Package name, or package specifier with version, like `name-1.0'. Be aware that packages are not always named the same and this module will not 'translate' them per
distro.
state: # (required) Whether to install (`present', or remove (`absent') a package. Other states depend on the underlying package module, i.e `latest'.
use: # The required package manager module to use (yum, apt, etc). The default 'auto' will use existing facts or try to autodetect it. You should only use this field if the automatic
selection is not working for some reason.
常用选项:
name 指定要安装的软件包名
state: present 安装 absent 卸载
案例1:
~~~
[admin@node1 ~]$ ansible webserver -m package -a "name=openssl-devel state=present" -b --ask-sudo-pass
[DEPRECATION WARNING]: The sudo command line option has been deprecated in favor of the "become" command line arguments. This feature will be removed in version 2.6. Deprecation warnings can be disabled by
setting deprecation_warnings=False in ansible.cfg.
SUDO password:
192.168.20.138 | SUCCESS => {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"1:openssl-devel-1.0.2k-8.el7.x86_64 providing openssl-devel is already installed"
]
}
192.168.20.137 | SUCCESS => {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"1:openssl-devel-1.0.2k-8.el7.x86_64 providing openssl-devel is already installed"
]
}
~~~
案例2:
~~~
- name: install_from_source | Ensure dependencies for building from source are installed.
package: "name={{ item }} state=installed"
with_items: "{{ php_packages }}"
~~~
- 第一章:Ansible基础入门
- 第二章:Ansible系列手册
- 第一节:Ansible系列之主机清单
- 第二节:Ansible系列之变量
- 第三节:Ansible系列之YAML
- 第四节:Ansible系列之条件判断
- 第五节:Ansible系列之循环
- 第六节: Ansible系列之tags
- 第七节:Ansible系列之Jinja2
- 第三章:Ansible系列之模块
- 第一节:user模块
- 第二节:group模块
- 第三节:cron模块
- 第四节:copy模块
- 第五节: file模块
- 第六节:yum模块
- 第七节:service模块
- 第八节:shell模块
- 第九节:script模块
- 第十节:setup模块
- 第十一节:filesystem和mount模块
- 第十二节:synchronize模块
- 第十三节: get_url模块
- 第十四节: package模块
- 第十五节:stat模块
- 第十六节:unarchive模块
- 第十七节: commang模块
- 第四章:Ansible-playbook介绍
- 第五章:Ansible系统环境
- 第一节:Ansible Role 系统环境之epel设置