platform-nginx.yml 1.27 KB
---
- hosts: platform-nginx
  remote_user: root
  vars_prompt:
    - name: "confirmation"
      prompt: "Sync and reload platform nginx. Please Enter [YES] to continue"
      private: no
  vars_files:
    - extra_vars/all.yml
  vars:
    - path: /Data/local/nginx-1.8.0

  tasks:
    # make sure path exist
    - name: "make sure path exist"
      shell: ls {{ path }}
      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:
        - platform-nginx

    - name: copy  conf files to nginx
      template:
        src: 'platform-nginx/vhost/{{ item }}'
        dest: "{{ path }}/conf/vhost/"
      with_items:
        - 'admin.portal.yohobuy.com.conf'
        - 'api.platform.yohoops.org.conf'
        - 'shopmanage.yohobuy.com.conf'
        - 'shops.yohobuy.com.conf'

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

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