ansible-playbook一键部署wordpress项目

- hosts: webserver,database
  remote_user: root
  gather_facts: no
  vars:
    - NGINX_USER: nginx
    - NGINX_PORT: 80
    - NGINX_FORKS: 2
    - BASE_DIR: "/usr/share/nginx/wordpress"
    - MYSQL_DB: wordpress
    - MYSQL_USER: wordpress
    - MYSQL_PASSWD: "Xs123456"
    - MYSQL_HOST: "%"
  tasks:
    - name: "step1: 安装数据库"
      yum: name=mariadb-server,mariadb state=present
      #service: name=mariadb state=started enabled=yes
      when: name == 'db'
      tags: install_db

    - name: "step2: 安装php和nginx的源"
      yum: name={{ item }}
      with_items:
        - epel-release
        - http://rpms.remirepo.net/enterprise/remi-release-7.rpm
      when: name == 'web'
      tags: install_yumrepo

    - name: "step3: 安装php8和nginx"
      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,nginx state=present
      when: name == 'web'
      tags: install_php_nginx

    - name: "step4: 启动数据库"
      service: name=mariadb state=started enabled=yes
      when: name == 'db'
      tags: start_db

    - name: "step5: 配置nginx"
      template: src=./nginx.conf dest=/etc/nginx/nginx.conf
      when: name == 'web'
      tags: nginx_conf

    - name: "step6: 启动PHP和nginx"
      service: name={{ item }} state=started
      with_items:
        - php80-php-fpm
        - nginx
      when: name == 'web'
      tags: start_php_nginx

    - name: "step7: 创建数据库"
      shell: mysql -e "create database if not exists {{ MYSQL_DB }}; grant all on {{ MYSQL_DB }}.* to '{{ MYSQL_USER }}'@'{{ MYSQL_HOST }}' identified by '{{ MYSQL_PASSWD }}'; flush privileges"
      when: name == 'db'
      tags: create_db

    - name: "step8: 上传wordpress代码"
      copy: src=/opt/wordpress dest=/usr/share/nginx mode=777
      when: name == 'web'
      tags: push_code

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值