ansible自动部署wordpress
时间: 2023-12-05 20:40:48 浏览: 143
以下是使用Ansible自动部署WordPress的步骤:
1.安装Ansible
2.创建Ansible inventory文件,指定需要部署WordPress的服务器IP地址
3.创建Ansible playbook文件,包含以下任务:
- 安装Apache、PHP、MySQL等必要的软件
- 下载WordPress并解压到指定目录
- 配置WordPress数据库连接信息
- 配置Apache虚拟主机
- 启动Apache和MySQL服务
4.运行Ansible playbook文件,执行自动化部署任务
下面是一个简单的Ansible playbook文件示例,用于自动部署WordPress:
```yaml
---
- name: Deploy WordPress
hosts: webserver
become: true
vars:
http_port: 80
mysql_root_password: your_password_here
db_name: wordpress
db_user: wordpress
db_password: your_password_here
wp_dir: /var/www/html/wordpress
tasks:
- name: Install Apache, PHP, MySQL
apt:
name: "{{ item }}"
state: present
with_items:
- apache2
- php
- php-mysql
- mysql-server
- libapache2-mod-php
- name: Download WordPress
get_url:
url: "https://wordpress.org/latest.tar.gz"
dest: /tmp/wordpress.tar.gz
- name: Extract WordPress
unarchive:
src: /tmp/wordpress.tar.gz
dest: "{{ wp_dir }}"
remote_src: yes
- name: Configure WordPress database
mysql_db:
name: "{{ db_name }}"
state: present
login_user: root
login_password: "{{ mysql_root_password }}"
- name: Create WordPress database user
mysql_user:
name: "{{ db_user }}"
password: "{{ db_password }}"
priv: "{{ db_name }}.*:ALL"
state: present
login_user: root
login_password: "{{ mysql_root_password }}"
- name: Configure Apache virtual host
template:
src: templates/wordpress.conf.j2
dest: /etc/apache2/sites-available/wordpress.conf
notify:
- Reload Apache
- name: Enable Apache virtual host
apache2_module:
state: present
name: rewrite
notify:
- Reload Apache
- name: Disable default Apache site
apache2_module:
state: absent
name: autoindex
notify:
- Reload Apache
- name: Enable WordPress Apache site
apache2_site:
state: present
name: wordpress
notify:
- Reload Apache
handlers:
- name: Reload Apache
service:
name: apache2
state: reloaded
```
阅读全文