- name: Deploy edxapp
  hosts: all
  become: True
  gather_facts: True
  vars:
    serial_count: 1
    CLUSTER_NAME: 'edxapp'
    NGINX_ENABLE_SSL: False
  serial: "{{ serial_count }}"
  roles:
   - role: aws
     when: COMMON_ENABLE_AWS_ROLE
   - role: automated
     AUTOMATED_USERS: "{{ EDXAPP_AUTOMATED_USERS | default({}) }}"
   - role: nginx
     nginx_sites:
     - lms
     - cms
     nginx_default_sites: "{{ EDXAPP_NGINX_DEFAULT_SITES }}"
     nginx_extra_sites: "{{ NGINX_EDXAPP_EXTRA_SITES }}"
     nginx_extra_configs: "{{ NGINX_EDXAPP_EXTRA_CONFIGS }}"
     nginx_skip_enable_sites: "{{ EDXAPP_NGINX_SKIP_ENABLE_SITES }}"
   - edxapp
   - role: sqlite_fix
     when: devstack is defined and devstack
   - role: datadog
     when: COMMON_ENABLE_DATADOG
   - role: splunkforwarder
     when: COMMON_ENABLE_SPLUNKFORWARDER
   - role: newrelic_infrastructure
     when: COMMON_ENABLE_NEWRELIC_INFRASTRUCTURE
   - role: minos
     when: COMMON_ENABLE_MINOS
   - role: datadog-uninstall
     when: not COMMON_ENABLE_DATADOG
   - role: hermes
     when: "EDXAPP_HERMES_ENABLED"
     HERMES_JITTER: 600
     HERMES_ALLOWED_SUDO_COMMANDS:
       - "/bin/cp {{ hermes_download_dir }}/lms.yml {{ COMMON_CFG_DIR }}/lms.yml"
       - "/bin/cp {{ hermes_download_dir }}/studio.yml {{ COMMON_CFG_DIR }}/studio.yml"
       - "/edx/app/edxapp/reload_lms_config.sh"
       - "/edx/app/edxapp/reload_cms_config.sh"
     HERMES_SERVICE_CONFIG:
       - url: '{{ HERMES_REMOTE_FILE_LOCATION }}/{{ COMMON_ENVIRONMENT }}/lms.yml'
         filename: '{{ hermes_download_dir }}/lms.yml'
         command:  "sudo /bin/cp {{ hermes_download_dir }}/lms.yml {{ COMMON_CFG_DIR }}/lms.yml && sudo /edx/app/edxapp/reload_lms_config.sh"
         secret_key_files: "{{ HERMES_PRIVATE_KEYS_DICT | map('regex_replace','(.*)','/edx/app/hermes/hermes-\\1') | join(',') if HERMES_PRIVATE_KEYS_DICT is defined else None }}"
       - url: '{{ HERMES_REMOTE_FILE_LOCATION }}/{{ COMMON_ENVIRONMENT }}/studio.yml'
         filename: '{{ hermes_download_dir }}/studio.yml'
         command:  "sudo /bin/cp {{ hermes_download_dir }}/studio.yml {{ COMMON_CFG_DIR }}/studio.yml && sudo /edx/app/edxapp/reload_cms_config.sh"
         secret_key_files: "{{ HERMES_PRIVATE_KEYS_DICT | map('regex_replace','(.*)','/edx/app/hermes/hermes-\\1') | join(',') if HERMES_PRIVATE_KEYS_DICT is defined else None }}"
