linux系统ansible工具的剧本发布workpress剧本编写

workpress剧本编写

      • 发布workpress
        • 整体剧本编写
          • 准备环境
          • 剧本编写
          • 浏览器安装workpress
        • 角色剧本编写
          • roles.yaml
          • php目录
          • nginx目录
          • mariadb目录
          • wordpress目录
          • 浏览器安装workpress

发布workpress

整体剧本编写
准备环境
上传workpress压缩包到/root目录

编写/root/nginx.conf文件,下面代码写入http模块的server中
vim /root/nginx.conf

location / {
            root   /usr/share/nginx/html/wordpress/;
            index  index.php index.html index.htm;
        }
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/wordpress/$fastcgi_script_name;
            include        fastcgi_params;
        }
剧本编写
vim workpress.yaml

---
- hosts: 10.12.153.110
  remote_user: root
  vars:
  tasks:
  - name: 安装数据库
    yum: name=mariadb-server,mariadb state=present
  - name: 安装php
    yum: name=http://rpms.remirepo.net/enterprise/remi-release-7.rpm state=present 
  - 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: 安装nginx
    yum: name=epel-release,nginx state=present
  - name: 启动环境
    service: name=nginx state=started enabled=yes
  - name: 启动环境
    service: name=php80-php-fpm state=started enabled=yes
  - name: 启动数据库
    service: name=mariadb state=started enabled=yes
  - name: 创建用户并授权
    shell: mysql -e "create database wordpress;grant all on wordpress.* to 'wordpress'@'localhost' identified by '0';grant all on wordpress.* to 'wordpress'@'%' identified by '0';flush privileges"
  - name: 拷贝nginx配置文件
    template: src=/root/nginx.conf dest=/etc/nginx/nginx.conf backup=yes
  - name: 安装解压工具
    yum: name=unzip state=present
  - name: 上传wordpress源码包
    unarchive: src=wordpress-6.2.2-zh_CN.tar.gz dest=/usr/share/nginx/html  mode=777 owner=nginx group=nginx
  - name: 重启nginx
    service: name=nginx state=restarted
浏览器安装workpress
数据库名字:workpress
用户名字:workpress
用户密码:0
数据库地址:数据库安装的服务器ip
角色剧本编写
ansible-galaxy init php
ansible-galaxy init mariadb
ansible-galaxy init nginx
ansible-galaxy init wordpress
touch roles.yaml
roles.yaml
vim roles.yaml

---
- hosts: ip
  remote_user: root
  roles:
    - nginx
    - php
    - mariadb
    - wordpress
    
#如果需要数据库和web分离可以这样写
#---
#- hosts: web端ip
#  remote_user: root
#  roles:
#    - nginx
#    - php
#    - wordpress
#- hosts: db端ip
#  remote_user: root
#  roles:
#    - mariadb
php目录
vim php/tasks/main.yml 

---
# tasks file for php
- 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=absent

- name: 安装php源
  yum: name=http://rpms.remirepo.net/enterprise/remi-release-7.rpm state=present

- 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: 启动环境
  service: name=php80-php-fpm state=started enabled=yes
nginx目录
vim nginx/template/nginx.comf

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
   
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /usr/share/nginx/html/wordpress/;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/wordpress/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}
vim nginx/tasks/main.yml 

---
# tasks file for nginx
- name: 卸载nginx
  yum: name=nginx state=absent
- name: 安装nginx
  yum: name=epel-release,nginx state=present
- name: 拷贝nginx.conf文件
  template: src=nginx.conf dest=/etc/nginx/nginx.conf backup=yes
- name: 启动nginx
  service: name=nginx state=started
mariadb目录
vim mariadb/tasks/main.yml 

---
# tasks file for mariadb
- name: 卸载数据库
  yum: name=mariadb-server,mariadb state=absent
- name: 安装数据库
  yum: name=mariadb-server,mariadb state=present
- name: 启动数据库
  service: name=mariadb state=started enabled=yes
- name: 删除数据库
  shell:  mysql -e "drop database wordpress;"
- name: 创建用户并授权
  shell: mysql -e "create database wordpress;grant all on wordpress.* to 'wordpress'@'localhost' identified by '0';grant all on wordpress.* to 'wordpress'@'%' identified by '0';flush privileges"
wordpress目录
上传wordpress压缩包到wordpress/files/
vim wordpress/tasks/main.yml 

---
# tasks file for wordpress
- name: 安装工具
  yum: name=unzip state=present
- name: 上传wordpress源码包
  unarchive: src=wordpress-6.2.2-zh_CN.tar.gz dest=/usr/share/nginx/html  mode=777 owner=nginx group=nginx
浏览器安装workpress
数据库名字:workpress
用户名字:workpress
用户密码:0
数据库地址:数据库安装的服务器ip

你可能感兴趣的:(linux,linux,ansible,android)