ansible部署wordpress架构
环境准备
playbook编写
- hosts: [web_group]
tasks:
- name: stop firewalld server
service:
name: firewalld
state: stopped
- name: disabled selinux
selinux:
state: disabled
- name: create www group
group:
name: www
gid: 666
state: present
- name: create www user
user:
name: www
uid: 666
group: '666'
shell: /sbin/nologin
create_home: no
state: present
- name: install nginx server
yum:
name: nginx
state: present
- name: configure nginx conf
copy:
src: /root/nginx/nginx.conf
dest: /etc/nginx/
owner: root
group: root
mode: 0644
- name: configure blog conf
copy:
src: /root/nginx/blog.conf
dest: /etc/nginx/conf.d/
owner: root
group: root
mode: 0644
- name: create code directory
file:
path: /code
state: directory
owner: www
group: www
- name: unzip wordpress
unarchive:
src: /root/nginx/wordpress-5.7.2-zh_CN.tar.gz
dest: /code
- name: unzaip php
unarchive:
src: /root/nginx/php.tgz
dest: /tmp
- name: install php-fpm server
shell: 'rpm -Uvh /tmp/*.rpm'
ignore_errors: yes
- name: configure php conf
copy:
src: /root/nginx/www.conf
dest: /etc/etc/php-fpm.d/
owner: root
group: root
mode: 0644
- name: start nginx server
service:
name: nginx
state: started
enabled: yes
- name: start php-fpm server
service:
name: php-fpm
state: started
enabled: yes
- name: yum install nfs
yum:
name: nfs-utils
state: present
- hosts: db01
tasks:
- name: Install Mariadb Server
yum:
name:
- mariadb-server
- MySQL-python
state: present
- name: Start Mariadb Server
service:
name: mariadb
state: started
enabled: yes
- name: Create wordpress User
mysql_user:
name: www
state: present
priv: '*.*:ALL'
host: '%'
password: '123'
- name: Create wordpress Database
mysql_db:
name: www
state: present
encoding: utf8
- hosts: [nfs_group]
tasks:
- name: stop rirewalld server
service:
name: firewalld
state: stopped
- name: disabled selinux
selinux:
state: disabled
- name: create www group
group:
name: www
gid: 666
state: present
- name: create www user
user:
name: www
uid: 666
group: '666'
shell: /sbin/nologin
create_home: no
state: present
- name: install nfs
yum:
name: nfs-utils
state: present
- name: nfs conf
copy:
content: /data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
dest: /etc/exports
- name: create nfs directory
file:
path: /data
state: directory
owner: www
group: www
mode: 0755
- name: strat nfs
service:
name: nfs-server
state: started
enabled: yes
- hosts: [web_group]
tasks:
- name: create wp-uploads
file:
path: /code/wordpress/wp-content/uploads
state: directory
owner: www
group: www
- name: mount nfs
mount:
path: /code/wordpress/wp-content/uploads
src: 172.16.1.31:/data
fstype: nfs
state: mounted
安装wordpress
|