用途: 包管理器,通過包管理器安裝軟件
[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設置