以下为playbook标准的目录结构,以不同级别目录层级的文件进行拆分。
[root@localhost playbooks]# tree .
.
├── playbooks.yml
├── roles
│ ├── common
│ │ ├── files
│ │ ├── handlers
│ │ ├── meta
│ │ ├── tasks
│ │ │ └── main.yml
│ │ └── vars
│ ├── mysql
│ │ └── tasks
│ │ └── main.yml
│ ├── nginx
│ │ ├── handlers
│ │ │ └── main.yml
│ │ └── tasks
│ │ └── main.yml
│ └── php-fpm
│ └── tasks
│ └── main.yml
└── site.yml
site.yml,playbook主要配置文件
例:
---
- name: Install web
hosts: webserver
user: root
roles:
- common
- nginx
- mysql
../tasks/main.yml,任务文件
例:
---
- name: Install nginx
yum: name=nginx state=present
notify: start nginx
../handlers/main.yml,处理程序文件
例:
---
- name: start nginx
service: name=nginx state=started
../vars/main.yml,变量文件
例:
---
ntpserver: time.windows.com
../templates/,用于template调用
例:
---
- name: copy configure
template: src=nginx.conf dest=/etc/nginx/nginx.conf
../files/,其内的文件无需路径,直接引用
例:
---
- name: include files
- include: nginx.yml