## 軟件管理模塊[yum][1]
### 在命令行使用yum模塊安裝
```
ansible node2.test.com -m yum -a 'name=httpd'
```
### 選項

### 在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]
### 選項

### 在命令行使用方式
```
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