---
- name: Ensure git is installed
  apt: pkg=git
- name: Ensure that /var/docker exists
  file: path=/var/docker owner=deploy group=deploy state=directory
- name: Get the official discourse docker image
  command: git clone https://github.com/discourse/discourse_docker.git /var/docker creates=/var/docker/README.md
- name: Copy over app configuration
  template: src=app.yml dest=/var/docker/containers/app.yml owner=deploy group=deploy
- name: Bootstrap discourse app
  command: ./launcher bootstrap app chdir=/var/docker creates=/var/docker/shared/standalone/log/rails/production.log
- name: Start discourse app
  command: ./launcher start app chdir=/var/docker

- name: Generate the nginx config for the app
  template: src=discourse.morph.io dest=/etc/nginx/sites-available/ owner=root group=root mode=644
  notify: restart nginx

- name: Make the nginx site active
  command: ln -s /etc/nginx/sites-available/discourse.morph.io /etc/nginx/sites-enabled/discourse.morph.io creates=/etc/nginx/sites-enabled/discourse.morph.io
  notify: restart nginx

---
- name: Ensure git is installed
  apt: pkg=git
- name: Ensure that /var/docker exists
  file: path=/var/docker owner=deploy group=deploy state=directory
- name: Get the official discourse docker image
  command: git clone https://github.com/discourse/discourse_docker.git /var/docker creates=/var/docker/README.md
- name: Copy over app configuration
  template: src=app.yml dest=/var/docker/containers/app.yml owner=deploy group=deploy

# launcher bootstrap needs a key pair at /home/vagrant/.ssh/id_rsa otherwise it waits
- name: Ensure vagrant .ssh directory exists
  file: path=/home/vagrant/.ssh owner=vagrant group=vagrant state=directory
- name: Generate vagrant keypair
  command: ssh-keygen -f /home/vagrant/.ssh/id_rsa -t rsa -N '' creates=/home/vagrant/.ssh/id_rsa
- name: Ensure private key has correct permissions and ownership
  file: path=/home/vagrant/.ssh/id_rsa owner=vagrant group=vagrant
- name: Ensure public key has correct permissions and ownership
  file: path=/home/vagrant/.ssh/id_rsa.pub owner=vagrant group=vagrant

- name: Bootstrap discourse app
  command: ./launcher bootstrap app chdir=/var/docker creates=/var/docker/shared/standalone/log/rails/production.log

- name: Start discourse app
  command: ./launcher start app chdir=/var/docker

- name: Generate the nginx config for the app
  template: src=discourse.morph.io dest=/etc/nginx/sites-available/ owner=root group=root mode=644
  notify: restart nginx

- name: Make the nginx site active
  command: ln -s /etc/nginx/sites-available/discourse.morph.io /etc/nginx/sites-enabled/discourse.morph.io creates=/etc/nginx/sites-enabled/discourse.morph.io
  notify: restart nginx

Install ssh keypair so discourse bootstrap works unaided
Install ssh keypair so discourse bootstrap works unaided
