---

- name: install dependencies
  apt:
    pkg: websockify

- name: ensure mumble user is present
  user:
    name: "mumble"
    home: "/srv/mumble"
    shell: "/bin/bash"
    state: present


- name: install mumble-web
  git:
    repo: "https://github.com/johni0702/mumble-web"
    dest: "/srv/mumble/mumble-web"
    force: true
  become: true
  become_user: "mumble"


- name: copy mumble-web unit file
  template:
    src: mumble-web-proxy.service.j2
    dest: /etc/systemd/system/mumble-web-proxy.service
    owner: root
    group: root
    mode: 0644
  register: servicefile
  notify: restart mumble-web-proxy

- name: Allow to python to inherit socket binding capability
  capabilities:
    path: /usr/bin/python2.7
    capability: cap_net_bind_service=ei
  when: servicefile.changed

- name: configure mumble-web
  template:
    src: config.local.js.j2
    dest: "{{ mumble_web_path }}/dist/config.local.js"
    owner: root
    group: root
    mode: 0644

- name: enable and start mumble-web
  systemd:
    name: mumble-web-proxy
    daemon-reload: yes
    enabled: True
    state: started
