---
# yamllint disable rule:line-length
- name: vérification des variables obligatoire
  fail:
    msg: |
      il faut définir les variables `coturn_hostname` et
      `coturn_secret` pour utiliser ce role
  when: (coturn_secret is not defined) or
        (coturn_hostname is not defined)

- name: ajout du server turn
  blockinfile:
    path: /usr/share/bbb-web/WEB-INF/classes/spring/turn-stun-servers.xml
    marker: "<!-- {mark} ANSIBLE MANAGED turn1 -->"
    insertbefore: '    <bean id="stunTurnService" class="org.bigbluebutton.web.services.turn.StunTurnService">'
    block: |
      <bean id="turn1" class="org.bigbluebutton.web.services.turn.TurnServer">
        <constructor-arg index="0" value="{{ coturn_secret  }}"/>
        <constructor-arg index="1" value="turn:{{ coturn_hostname }}:443?transport=tcp"/>
        <constructor-arg index="2" value="86400"/>
      </bean>
  notify:
    - restart bigbluebutton

- name: ajout du server turns
  blockinfile:
    path: /usr/share/bbb-web/WEB-INF/classes/spring/turn-stun-servers.xml
    marker: "<!-- {mark} ANSIBLE MANAGED turn2 -->"
    insertbefore: '    <bean id="stunTurnService" class="org.bigbluebutton.web.services.turn.StunTurnService">'
    block: |
      <bean id="turn2" class="org.bigbluebutton.web.services.turn.TurnServer">
        <constructor-arg index="0" value="{{ coturn_secret  }}"/>
        <constructor-arg index="1" value="turns:{{ coturn_hostname }}:443?transport=tcp"/>
        <constructor-arg index="2" value="86400"/>
      </bean>
  notify:
    - restart bigbluebutton

- name: ajout du server stun
  lineinfile:
    path: /usr/share/bbb-web/WEB-INF/classes/spring/turn-stun-servers.xml
    regexp: '        <constructor-arg index="0" value="stun:stun.l.google.com:19302"/>'
    line: '        <constructor-arg index="0" value="stun:{{ coturn_hostname }}"/>'
  notify:
    - restart bigbluebutton

- name: activation du server turn
  lineinfile:
    path: /usr/share/bbb-web/WEB-INF/classes/spring/turn-stun-servers.xml
    regexp: '                <!--ref bean="turn1" /-->'
    line: '                <ref bean="turn1" />'
  notify:
    - restart bigbluebutton

- name: activation du server turns
  lineinfile:
    path: /usr/share/bbb-web/WEB-INF/classes/spring/turn-stun-servers.xml
    regexp: '                <!--ref bean="turn2" /-->'
    line: '                <ref bean="turn2" />'
  notify:
    - restart bigbluebutton
# yamllint enable rule:line-length
