#
# Copyright (c) 2020 Bubble, Inc.  All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
#
- name: Create algo staging directory
  file:
    path: /root/ansible/roles/algo/algo
    owner: root
    group: root
    mode: 0770
    state: directory

- name: Download algo dist file
  get_url:
    url: https://jenkins.bubblev.org/public/releases/algo/{{ algo_version }}/algo.zip
    dest: /tmp/algo.zip
    checksum: sha256:{{ algo_sha }}

- name: Unzip algo master.zip
  unarchive:
    remote_src: yes
    src: /tmp/algo.zip
    dest: /root/ansible/roles/algo

- name: Write algo config.cfg.hbs
  copy:
    src: config.cfg.hbs
    dest: /root/ansible/roles/algo/algo/config.cfg.hbs

- name: Write prep_algo.sh script
  copy:
    src: prep_algo.sh
    dest: /root/ansible/roles/algo/algo/prep_algo.sh
    owner: root
    group: root
    mode: 0700

- name: Run prep_algo.sh
  shell: /root/ansible/roles/algo/algo/prep_algo.sh

- name: Install algo_refresh_users script and monitor
  copy:
    src: "{{ item }}"
    dest: "/usr/local/bin/{{ item }}"
    owner: root
    group: root
    mode: 0500
  with_items:
    - "algo_refresh_users.sh"
    - "algo_refresh_users_monitor.sh"

- name: Install algo_refresh_users_monitor supervisor conf file
  copy:
    src: supervisor_algo_refresh_users_monitor.conf
    dest: /etc/supervisor/conf.d/algo_refresh_users_monitor.conf

- name: Install wg_monitor_connections script
  copy:
    src: wg_monitor_connections.sh
    dest: "/usr/local/sbin/wg_monitor_connections.sh"
    owner: root
    group: root
    mode: 0500

- name: Install wg_monitor_connections supervisor conf file
  copy:
    src: supervisor_wg_monitor_connections.conf
    dest: /etc/supervisor/conf.d/wg_monitor_connections.conf

- include: algo_packer.yml
