使用Ansible编写playbook自动化安装php7.3.14

准备条件

  1. ansible centos自带,就不在赘述安装。
  2. 配置好ansible的host,这块自查搜索引擎;
  3. php包及libzip.tar.gz需要自己下载到指定文件夹;

以下是纯playbook

---
- hosts: web
  tasks:
    - name: "install php 依赖包"
      yum:
        name:
          - epel-release
          - cmake3
          - cmake
          - libxml2-devel
          - bzip2-devel
          - curl-devel
          - libjpeg-devel
          - libpng-devel
          - freetype-devel
          - libxslt-devel
          - ncurses-devel
          - make
          - apr*
          - autoconf
          - automake
          - curl
          - curl-devel
          - gcc
          - gcc-c++
          - zlib-devel
          - openssl
          - openssl-devel
          - pcre-devel
          - libicu-devel
        state: latest
    - name: "传输包php,解压"
      unarchive: src=/usr/local/src/ansible_install_php/pkg/php-7.3.14.tar.gz dest=/usr/local/src/
    - name: "传输libzip.tar.gz"
      unarchive: src=/usr/local/src/ansible_install_php/pkg/libzip.tar.gz dest=/usr/local/src/
    - name: "make && make install libzip"
      shell: cd /usr/local/src/libzip-1.5.1 && mkdir build && cd build && cmake3 .. && make && make install
    - name: "动态链接库生效"
      shell: echo -e '/usr/local/lib64 \n/usr/local/lib \n/usr/lib \n/usr/lib64'>>/etc/ld.so.conf && ldconfig -v


    - name: "生成Makefile"
      shell: ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --with-pear --with-gettext --with-curl --with-xmlrpc --with-openssl --with-mhash --with-gd --enable-fpm --enable-mysqlnd --enable-mysqlnd-compression-support --enable-xml --enable-rpath --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --enable-gd-jis-conv --enable-pcntl --enable-sockets --enable-calendar --enable-zip --enable-soap --enable-fileinfo --enable-opcache --enable-maintainer-zts
      args:
        chdir: /usr/local/src/php-7.3.14
    - name: "make && make install"
      shell: make -j2 && make install
      args:
        chdir: /usr/local/src/php-7.3.14
    - name: "配置文件cp"
      copy: src=/usr/local/src/ansible_install_php/templates/php.ini dest=/usr/local/php/etc/
    - name: "www.conf"
      copy: src=/usr/local/src/ansible_install_php/templates/www.conf dest=/usr/local/php/etc/php-fpm.d
    - name: "配置文件php-fpm.conf"
      shell: cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    - name: "开机启动配置copy"
      shell: cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
      args:
        chdir: /usr/local/src/php-7.3.14
    - name: "用户创建"
      user:
        name: www
        state: present
    - name: "服务启动"
      service:
        name: php-fpm
        enabled: yes
        state: restarted

 

你可能感兴趣的:(Shell编程,自动化运维,ansible,运维,centos)