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