#
# Copyright (c) 2020 Bubble, Inc.  All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
#
- name: Snapshot ansible roles in the background
  command: bash -c "/usr/local/bin/snapshot_ansible.sh &"

- name: Touch first-time setup file
  shell: su - bubble bash -c "if [[ ! -f /home/bubble/first_time_marker ]] ; then echo -n install > /home/bubble/first_time_marker ; fi"
  when: restore_key is not defined

- name: Touch first-time setup file (restore)
  shell: su - bubble bash -c "if [[ ! -f /home/bubble/first_time_marker ]] ; then echo -n restore > /home/bubble/first_time_marker ; fi"
  when: restore_key is defined

- name: Install mitmproxy CA cert in local CA store
  shell: install_cert.sh /home/mitmproxy/.mitmproxy/{{ cert_name }}-ca-cert.pem 600
  when: install_type == 'node'

- name: Install mitmproxy public certs in bubble dir
  shell: /usr/local/bin/copy_certs_to_bubble.sh {{ cert_name }}
  when: install_type == 'node'

- name: Install bubble supervisor conf file
  template:
    src: "supervisor_bubble.conf.j2"
    dest: /etc/supervisor/conf.d/bubble.conf

# We cannot receive notifications until nginx is running, so start bubble API as the very last step
- name: reload supervisord
  shell: supervisorctl reload

- name: Ensure authorized SSH keys are up-to-date
  shell: su - bubble bash -c "touch /home/bubble/.refresh_ssh_keys"
