ansible-playbook script to implement wordpress online

Prepare the environment:

1. Three servers are required: host server (10.36.192.129), db server (10.36.192.131), and web server (10.36.192.130). The scripts are all written on the host server.

2. The host server needs to do ansible analysis

vim /etc/ansible/hosts

[web]
10.36.192.130
[db]
10.36.192.131

3. The yum source here needs to be configured by yourself. I have a yum source server here.

 1: Script installation database

---
- hosts: db
  remote_user: root
  vars:
    - db_passwd: 'QianFeng@123'
    - db_name: 'wordpress'
  tasks:
    - name: 下载yum源
      shell: curl -o /opt/yum-server.sh http://10.36.192.100/yum-server.sh
    
    - name: 安装yum源
      shell: sh /opt/yum-server.sh

    - name: 安装数据库
      yum: name=mariadb-server,mariadb state=present disablerepo=mysql-5.7-community

    - name: 启动数据库
      service: name=mariadb state=started enabled=true
    
    - name: 配置数据库
      shell: mysql -e "create database {
   
   { db_name }}; grant all on wordpress.* to 'wordpress'@'%' identified by '{
   
   { db_passwd }}'; flush privileges"

 2. Script to install nginx, php, and go online with wordpress

hosts: web
remote_user: root
vars:

  - nginx_user: nginx
  - nginx_forks: auto
  - nginx_port: 80
    tasks:
  - name: 下载yum源
    shell: curl -o /opt/yum-server.sh http://10.36.192.100/yum-server.sh

  - name: 安装yum源
    shell: sh /opt/yum-server.sh

  - name: 安装nginx
    yum: name=nginx state=present

  - name: nginx配置文件
    template: src=/root/nginx.conf dest=/etc/nginx/

  - name: 启动Nginx
    service: name=nginx state=started enabled=true

  - name: 安装PHP
    yum: name=php80-php-xsl,php80-php,php80-php-cli,php80-php-devel,php80-php-gd,php80-php-pdo,php80-php-mysql,php80-php-fpm state=present

  - name: 启动PHP
    service: name=php80-php-fpm state=started enabled=true

  - name: 拷贝wordpress源代码
    unarchive: src=/root/wordpress-6.4.1-zh_CN.tar.gz dest=/usr/share/nginx/html

おすすめ

転載: blog.csdn.net/weixin_69654831/article/details/134507883