---
- name: Check if bbb_ssl_email is defined
  ansible.builtin.assert:
    that:
      - bbb_ssl_email != ""
  tags:
    - bbb-check_vars1

- name: Install LetsEncrypt enabled nginx config
  ansible.builtin.template:
    src: templates/bbb-ssl.conf.j2
    dest: /etc/nginx/sites-available/bigbluebutton
    backup: true
  tags:
    - bbb_install_nginx_ssl_conf

- name: Update http for https on nginx
  ansible.builtin.replace:
    path: /opt/freeswitch/conf/sip_profiles/external.xml
    regexp: '<param name="ws-binding"  value=":5066"/>'
    replace: '<param name="wss-binding"  value="{{ server_ip }}:7443"/>'
    backup: true
  tags:
    - bbb_enable_https

- name: Update http for https on nginx
  ansible.builtin.replace:
    path: /etc/bigbluebutton/nginx/sip.nginx
    regexp: 'http:'
    replace: 'https:'
    backup: true
  tags:
    - bbb_enable_https

- name: Update SIP port on nginx
  ansible.builtin.replace:
    path: /etc/bigbluebutton/nginx/sip.nginx
    regexp: '5066'
    replace: '7443'
    backup: true
  tags:
    - bbb_enable_https

- name: Update http for https on BigBlueButton webapp
  ansible.builtin.replace:
    path: "/usr/share/bbb-web/WEB-INF/classes/bigbluebutton.properties"
    regexp: 'bigbluebutton.web.serverURL=http:'
    replace: 'bigbluebutton.web.serverURL=https:'
    backup: true
  tags:
    - bbb_enable_https

- name: Update http for https on red5
  ansible.builtin.replace:
    path: /usr/share/red5/webapps/screenshare/WEB-INF/screenshare.properties
    regexp: 'jnlpUrl=http:'
    replace: 'jnlpUrl=https:'
    backup: true
  tags:
    - bbb_enable_https

- name: Update http for https on red5
  ansible.builtin.replace:
    path: /usr/share/red5/webapps/screenshare/WEB-INF/screenshare.properties
    regexp: 'jnlpFile=http:'
    replace: 'jnlpFile=https:'
    backup: true
  tags:
    - bbb_enable_https

- name: Update http for https on BigBlueButton client config
  ansible.builtin.replace:
    path: /var/www/bigbluebutton/client/conf/config.xml
    regexp: 'http://'
    replace: 'https://'
    backup: true
  tags:
    - bbb_enable_https

- name: Update http for https on BigBlueButton client config
  ansible.builtin.replace:
    path: /usr/local/bigbluebutton/core/scripts/bigbluebutton.yml
    regexp: 'playback_protocol: http$'
    replace: 'playback_protocol: https'
    backup: true
  tags:
    - bbb_enable_https

- name: Ansible check if /var/lib/tomcat7/webapps/demo/bbb_api_conf.jsp exists
  ansible.builtin.stat:
    path: /var/lib/tomcat7/webapps/demo/bbb_api_conf.jsp
  register: demo
  tags:
    - bbb_enable_https

- name: Update http for https on demo
  ansible.builtin.replace:
    path: /var/lib/tomcat7/webapps/demo/bbb_api_conf.jsp
    regexp: 'String BigBlueButtonURL = "http:'
    replace: 'String BigBlueButtonURL = "https:'
    backup: true
  when: demo.stat.exists == True
  tags:
    - bbb_enable_https
