请给出一个ansible-playbook 内含多个子任务
时间: 2024-03-20 17:40:01 浏览: 50
ansible-playbook
好的,这是一个简单的ansible playbook,它包含多个子任务:
```
---
- name: deploy web app
hosts: web_servers
become: yes
tasks:
- name: install dependencies
apt:
name: ['git', 'python3-pip', 'nginx']
state: present
- name: clone app repository
git:
repo: git://github.com/user/repo.git
dest: /var/www/app
version: master
- name: install app dependencies
pip:
requirements: /var/www/app/requirements.txt
- name: configure nginx
template:
src: /etc/nginx/nginx.conf.j2
dest: /etc/nginx/nginx.conf
owner: root
group: root
mode: 0644
notify: restart nginx
handlers:
- name: restart nginx
service:
name: nginx
state: restarted
```
这个playbook用于在web服务器上部署一个web应用程序,它包含以下子任务:
1. 安装依赖项
2. 克隆应用程序存储库
3. 安装应用程序依赖项
4. 配置nginx
此外,还定义了一个处理程序,用于在配置nginx文件后重启nginx服务。
阅读全文