Skip to content
Snippets Groups Projects
main.yml 6.68 KiB
---
- name: mediaserver install
  ansible.builtin.apt:
    force_apt_get: true
    install_recommends: false
    name: "{{ server_packages }}"
  register: apt_status
  retries: 60
  until: apt_status is success or ('Failed to lock apt for exclusive operation' not in apt_status.msg and '/var/lib/dpkg/lock' not in apt_status.msg)

- name: fetch ssh public key
  register: root_ssh_pubkey
  ansible.builtin.slurp:
    path: /root/.ssh/id_ed25519.pub
  tags: always

- name: register ssh public key as an ansible fact
  ansible.builtin.set_fact:
    pubkey: "{{ root_ssh_pubkey['content'] | b64decode }}"
  tags: always

- name: share ssh public key between cluster members
  loop: "{{ groups['mediaserver'] }}"
  ansible.posix.authorized_key:
    user: root
    key: "{{ hostvars[item]['pubkey'] }}"
  tags: always

- name: Update the MS configuration with the celerity server IP
  ansible.builtin.lineinfile:
    path: /etc/mediaserver/msconf.py
    regexp: "^CELERITY_SERVER_URL = "
    line: CELERITY_SERVER_URL = 'https://{{ server_celerity_server_url }}:6200'
    create: true
    owner: root
    group: root
    # 644 as all the instances must reach this file
    # The instances cannot be in a common group as of now => https://redmine.ubicast.net/issues/33046
    mode: "0644"

- name: Update the MS configuration with the celerity server secret
  ansible.builtin.lineinfile:
    path: /etc/mediaserver/msconf.py
    regexp: "^CELERITY_SIGNING_KEY = "
    line: CELERITY_SIGNING_KEY = '{{ server_celerity_signing_key }}'
    create: true
    owner: root
    group: root
    # 644 as all the instances must reach this file
    # The instances cannot be in a common group as of now => https://redmine.ubicast.net/issues/33046
    mode: "0644"

- name: create instances
  loop: "{{ server_instances }}"
  environment:
    MS_ID: "{{ item.ms_id }}"
    MS_SERVER_NAME: "{{ item.ms_server_name }}"
    MS_API_KEY: "{{ item.ms_api_key }}"
    CM_SERVER_NAME: "{{ item.cm_server_name }}"
    MS_SUPERUSER_PWD: "{{ item.ms_superuser_pwd }}"
    MS_ADMIN_PWD: "{{ item.ms_admin_pwd }}"
    DB_HOST: "{{ envsetup_db_host | d('127.0.0.1') }}"
    DB_PORT: "{{ envsetup_db_port | d('5432') }}"
    DB_PG_ROOT_PWD: "{{ envsetup_db_pg_root_pwd | d('') }}"
    MS_SECRET: "{{ envsetup_ms_secret | d('') }}"
  ansible.builtin.command:
    cmd: mscontroller.py add -u {{ item.name }}
    creates: /etc/nginx/sites-available/mediaserver-{{ item.name }}.conf
  throttle: 1