在macbook使用ansible

zhiqiang
brew install ansible

配置主机 sudo vim /etc/ansible/hosts

192.168.0.11 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=passwd

安装

brew install sshpass.rb

sshpass.rb

require 'formula'

class Sshpass < Formula
  url 'http://sourceforge.net/projects/sshpass/files/sshpass/1.09/sshpass-1.09.tar.gz'
  homepage 'http://sourceforge.net/projects/sshpass'
  sha256 '71746e5e057ffe9b00b44ac40453bf47091930cba96bbea8dc48717dedc49fb7'

  def install
    system "./configure", "--disable-debug", "--disable-dependency-tracking",
                          "--prefix=#{prefix}"
    system "make install"
  end

  def test
    system "sshpass"
  end
end

nginx-php-install-playbook.yml

---
---
- hosts: all
  remote_user: root
  vars:
    - PHP_VERSION: 7.4
    - GROUPUSER: www
  tasks:
    - name: 'create {{GROUPUSER}} group'
      group: name={{GROUPUSER}} state=present

    - name: 'create {{GROUPUSER}} user'
      user: name={{GROUPUSER}} group={{GROUPUSER}} state=present create_home=False shell=/sbin/nologin

    - name: 'update'
      shell: apt update

    - name: 'software-properties-common'
      apt: name=software-properties-common state=present

    - name: 'Add php repo'
      apt_repository: repo='ppa:ondrej/php'

    - name: 'update'
      shell: apt update

    - name: 'Install php{{PHP_VERSION}} software'
      apt:
        name: 
          - php{{PHP_VERSION}}-fpm
          - php{{PHP_VERSION}}-redis
          - php{{PHP_VERSION}}-common
          - php{{PHP_VERSION}}-bcmath
          - php{{PHP_VERSION}}-curl
          - php{{PHP_VERSION}}-gd
          - php{{PHP_VERSION}}-mbstring
          - php{{PHP_VERSION}}-mysql
          - php{{PHP_VERSION}}-xml
          - php{{PHP_VERSION}}-zip
          - php{{PHP_VERSION}}-swoole
        state: present

    - name: 'update php-fpm listen'
      lineinfile:
        dest: /etc/php/{{PHP_VERSION}}/fpm/pool.d/www.conf
        regexp: "listen = *"
        line: "listen = 127.0.0.1:9000"

    - name: 'update php-fpm group'
      lineinfile:
        dest: /etc/php/{{PHP_VERSION}}/fpm/pool.d/www.conf
        regexp: "listen.group = *"
        line: "listen.group = {{GROUPUSER}}"

    - name: 'update php-fpm owner'
      lineinfile:
        dest: /etc/php/{{PHP_VERSION}}/fpm/pool.d/www.conf
        regexp: "listen.owner = *"
        line: "listen.owner = {{GROUPUSER}}"
        
    - name: 'update php.ini'
      shell: 'echo "env=dev" >> /etc/php/{{PHP_VERSION}}/cli/conf.d/environment.ini && echo "env=dev" >> /etc/php/{{PHP_VERSION}}/fpm/conf.d/environment.ini'

    - name: "restart php{{PHP_VERSION}}-fpm"
      service: name='php{{PHP_VERSION}}-fpm' state=restarted
      
    - name: 'Install nginx'
      apt: name=nginx state=present

    - name: 'update nginx user'
      lineinfile:
        dest: /etc/nginx/nginx.conf
        regexp: "user www-data;"
        line: "user {{GROUPUSER}};"

    - name: 'chmod'
      shell: 'chmod -R 777 /var/lib/nginx/proxy'
    
    - name: "restart nginx"
      service: name=nginx state=restarted
阅读 267
218 声望
11 粉丝
0 条评论
你知道吗?

218 声望
11 粉丝
文章目录
宣传栏