ansible部署wordpress架构

ansible部署wordpress架构

环境准备

在这里插入图片描述

playbook编写

#web操作
- 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
#db01操作
- 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
#nfs操作
- 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

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值