---

- name: install git
  become: yes
  apt:
    name: git

- name: create docs application directory
  become: yes
  file:
    path: /opt/docs
    state: directory
    owner: ubuntu
    group: domain^users
    mode: u=rwx,g=rwx,o=

- name: update checkout
  git:
    repo: git@git.zooxlabs.com:zooxco/driving.git
    dest: /opt/docs
    version: master
    accept_hostkey: yes

- name: install nginx
  become: yes
  apt:
    name: nginx

- name: Configure nginx
  become: yes
  copy:
    src: nginx.conf
    dest: /etc/nginx/sites-enabled/docs

- name: Remove sites-enabled/default
  become: yes
  file:
     path: /etc/nginx/sites-enabled/default
     state: absent

- name: Remove sites-available/default
  become: yes
  file:
    path: /etc/nginx/sites-available/default
    state: absent

- name: Create ssl directory
  become: yes
  file:
    path: /etc/nginx/ssl
    state: directory
    mode: 0755

- name: Install SSL certificate
  become: yes
  copy:
    src: templates/zooxlabs_wildcard.crt
    dest: /etc/nginx/ssl/zooxlabs_wildcard.crt

- name: Install SSL private key
  become: yes
  copy:
    content: "{{ lookup('hashi_vault', 'secret=secret/cert/zooxlabs_wildcard').private_key }}"
    dest: /etc/nginx/ssl/zooxlabs_wildcard.key

# We may have swapped the config out from underneath it so let's reload just
# in case.
- name: Reload nginx
  become: yes
  service:
    name: nginx
    state: reloaded
