## 软件管理模块[yum][1]
### 在命令行使用yum模块安装
```
ansible node2.test.com -m yum -a 'name=httpd'
```
### 选项
![](http://om4h63cja.bkt.clouddn.com/17-7-11/66745584.jpg)
### 在playbook中这样使用
```
---
- name: yum test
hosts: b1.hi.com
tasks:
- name: yum install pkg
yum: name={{ item }} update_cache=True
with_items:
- git
- vim-enhanced
- tree
- screen
# 更新所有软件
- name: upgrade pkg
yum: updade_cache=yes upgrade=yes
```
### 示例
~~~
- name: install the latest version of Apache
yum:
name: httpd
state: latest
- name: remove the Apache package
yum:
name: httpd
state: absent
- name: install the latest version of Apache from the testing repo
yum:
name: httpd
enablerepo: testing
state: present
- name: install one specific version of Apache
yum:
name: httpd-2.2.29-1.4.amzn1
state: present
- name: upgrade all packages
yum:
name: '*'
state: latest
- name: install the nginx rpm from a remote repo
yum:
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
yum:
name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present
- name: install the 'Development tools' package group
yum:
name: "@Development tools"
state: present
- name: install the 'Gnome desktop' environment group
yum:
name: "@^gnome-desktop-environment"
state: present
- name: List ansible packages and register result to print with debug later.
yum:
list: ansible
~~~
---
## 服务管理[service][2]
### 选项
![](http://om4h63cja.bkt.clouddn.com/17-7-12/95013435.jpg)
### 在命令行使用方式
```
ansible node2.test.com -m service -a 'name=httpd state=started enabled=true'
ansible node2.test.com -m service -a 'name=network state=restarted args=eth0'
```
### 示例
~~~
# Example action to start service foo, based on running process /usr/bin/foo
- service:
name: foo
pattern: /usr/bin/foo
state: started
# Example action to restart network service for interface eth0
- service:
name: network
state: restarted
args: eth0
~~~
[1]:http://docs.ansible.com/ansible/yum_module.html
[2]:http://docs.ansible.com/ansible/service_module.html
- 目录
- ansible基础
- ansible简介
- ansible安装和测试
- ansible配置文件
- 常用命令
- yaml在ansible中的用法
- inventory
- 变量与facts
- when语句
- handler模块
- 大杂烩
- ansible模块
- assert 模块
- copy模块
- cron模块
- debug模块
- django_manage模块
- file模块
- filesystem模块
- git模块
- hostname模块
- lineinfile模块
- mount模块
- mysql_user模块
- mysql_db模块
- pip模块
- selinux
- setup模块
- shell 和 command 模块
- stat模块
- supervisorctl
- systemd
- timezone
- unarchive模块
- user模块
- wait_for
- yum和service模块
- 其他模块或者方法
- setup模块
- url模块
- slack 模块
- pause 模块
- 其他
- 报错处理
- playbooks
- 复杂的playbook
- 循环
- roles
- YAML
- jinja2