# 其他模块或者方法
1 等待s.hi.com的80端口开始监听再继续运行。
`wait for`
```
---
- name: wait for httpd server running
hosts: s.hi.com
tasks:
- name: wait for httpd server running
local_action: wait_for port=80 host=s.hi.com
```
2 将任务转移到其他主机上执行
`delegate_to`
```
---
- name: delegate tasks to other server
hosts: s.hi.com
tasks:
- name: delegate tasks to other server
copy: src=/tmp/a.txt dest=/tmp/b.txt
delegate_to: b1.hi.com
- name: common tasks
copy: src=/tmp/a.txt dest=/tmp/b.txt
```
3 并行执行play的主机数量,最大失败主机比例
```
---
- name: one by one
hosts: s.hi.com
serial: 1
# 当失败比例达到25%让整个play失败
max_fail_percentage: 25
```
4 只执行一次
场景:hosst指向的是多台主机,但只有一台运行数据库迁移
`run_once`
```
---
- name: run once test
hosts: b1.hi.com s.hi.com
tasks:
- name: run once test
shell: date >> /tmp/time.txt
run_once: true
```
5 生成ssl
```
- name: create virtualenv
hosts: web
vars:
proj_name: mezz
conf_path: /root/ssl
domain: www.mezz.com
tasks:
- name: create ssl certificates
command:
openssl req -new -x509 -nodes -out {{ proj_name }}.crt
-keyout {{ proj_name }}.key -subj '/CN={{ domain }}' -days 3650
chdir={{ conf_path }}
creates={{ conf_path }}/{{ proj_name }}.crt
```
- 目录
- ansible基础
- ansible简介
- ansible安装和测试
- ansible配置文件
- yaml在ansible中的用法
- inventory
- 变量与facts
- when语句
- handler模块
- 大杂烩
- ansible模块
- copy模块
- cron模块
- debug模块
- django_manage模块
- file模块
- git模块
- hostname模块
- lineinfile模块
- mysql_user模块
- mysql_db模块
- pip模块
- selinux
- setup模块
- shell 和 command模块
- stat模块
- supervisorctl
- systemd
- timezone
- unarchive模块
- user模块
- wait_for
- yum和service模块
- 其他模块或者方法
- 其他
- 报错处理
- playbooks
- 复杂的playbook
- 循环
- roles