#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
---
- name: install coturn
  apt:
    pkg:
    - coturn
    state: present
    policy_rc_d: 101
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: add turnserver user to group ssl-cert,letsencrypt
  user:
    name: "turnserver"
    groups: "ssl-cert"
    append: yes
    createhome: no
    state: present


- name: copy turnserver.conf
  copy:
    src: "{{item}}"
    dest: "/etc/turnserver.conf"
    mode: 0640
    owner: "root"
    group: "turnserver"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/turnserver.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/turnserver.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/turnserver.conf"
    - "default/turnserver.conf"
  notify: restart coturn.service


- name: enable and start coturn.service
  include_role: name="base/systemd/enable-and-start"
  vars:
    service_name: coturn.service
