用ansible编写一个自动部署脚本
时间: 2023-12-05 21:05:05 浏览: 154
好的,我明白您的问题,以下是一个简单的自动部署脚本的Ansible playbook示例:
```
- name: Deploy web application
hosts: all
become: true
tasks:
- name: Install required packages
apt:
name: "{{ item }}"
state: present
with_items:
- nginx
- python3
- python3-pip
- name: Install Python dependencies
pip:
requirements: requirements.txt
- name: Configure Nginx
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
- name: Start Nginx
systemd:
name: nginx
enabled: true
state: started
- name: Clone repository
git:
repo: https://github.com/your-repo.git
dest: /var/www/your-app
version: master
- name: Start application
command: python3 app.py
args:
chdir: /var/www/your-app
```
这个playbook将使用Ansible自动安装nginx和Python3,从git克隆应用程序代码, 安装依赖项, 配置Nginx并启动应用程序. 您可以使用此示例作为模板来编写您自己的自动化脚本。
阅读全文