---
- hosts: webservers

  sudo: yes

  tasks:

  - name: Write gunicorn config file
    template: src=assets/gunicorn.j2 dest=/etc/init/ecep.conf
    notify:
      - restart gunicorn

  - name: Write nginx config file
    template: src=assets/nginx.j2 dest=/etc/nginx/sites-available/ecep.conf
    notify:
      - restart nginx

  - name: Link nginx config to sites-enabled
    file: state=link src=/etc/nginx/sites-available/ecep.conf path=/etc/nginx/sites-enabled/ecep
    notify:
      - restart nginx

  - name: Remove default nginx config
    file: state=absent path=/etc/nginx/sites-enabled/default
    notify:
      - restart nginx

  handlers:
  - name: restart nginx
    action: service name=nginx state=restarted

  - name: restart gunicorn
    action: service name=ecep state=restarted
---
- hosts: webservers

  sudo: yes

  tasks:

  - name: Write gunicorn config file
    template: src=assets/gunicorn.j2 dest=/etc/init/ecep.conf
    notify:
      - restart gunicorn

  - command: touch /etc/nginx/.htpasswd

  - name: Creating User/Password to sign into staging server
    command: htpasswd -b /etc/nginx/.htpasswd ${http_user} ${http_password}
    only_if: "'${http_password}' != '' and '${http_user}' != ''"

  - name: Write nginx config file
    template: src=assets/nginx.j2 dest=/etc/nginx/sites-available/ecep.conf
    notify:
      - restart nginx

  - name: Link nginx config to sites-enabled
    file: state=link src=/etc/nginx/sites-available/ecep.conf path=/etc/nginx/sites-enabled/ecep
    notify:
      - restart nginx

  - name: Remove default nginx config
    file: state=absent path=/etc/nginx/sites-enabled/default
    notify:
      - restart nginx

  handlers:
  - name: restart nginx
    action: service name=nginx state=restarted

  - name: restart gunicorn
    action: service name=ecep state=restarted
Create password from using apache htpasswd command
Create password from using apache htpasswd command
