1 将任务转移到其他主机上执行
`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
```
2 并行执行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模块
- 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