crm-nginx.yml 1.49 KB
# crm and store nginx

- hosts: crm-store-nginx
  remote_user: root
  vars_files:
    - extra_vars/all.yml
  vars_prompt:
    - name: "confirmation"
      prompt: "Sync and reload crm and store nginx. Please Enter [YES] to continue"
      private: no
    - name: "upstream_az"
      prompt: "Choose which az's upstream: [local|gray] "
      default: 'local'
      private: no

  vars:
    - path: /usr/local/openresty
  tasks:
    # make sure path exist
    - name: "make sure path exist"
      shell: ls /usr/local/openresty
      ignore_errors: True
      register: result

    - name: "make sure nginx path exist"
      fail:
        msg: " nginx {{ path }} not exist!"
      when:  result is failed

    #  make sure group exists
    - name: make sure groups exist in inventory file
      fail:
        msg: "group {{ item }} not exist!"
      when: item not in groups
      with_items:
        - crm-store-nginx
        - java-shops
        - java-portal-gateway
        - java-extendstore
        - java-crm
    
    - name: copy vhosts conf files to nginx
      template:
        src: 'crm-nginx/vhosts/{{ item }}'
        dest: "{{ path }}/nginx/conf/vhosts/"
      with_items:
        - 'adminstore.yohobuy.conf'
        - 'crm.conf'
        - 'extstore.conf'
        - 'shop.conf'

    - name: update nginx upstream for nginx.conf
      template:
        src: 'crm-nginx/nginx.conf.j2'
        dest: "{{ path }}/nginx/conf/nginx.conf"

    - name: reload nginx
      command: "{{ path }}/nginx/sbin/nginx -s reload"