---

# Stateless app server configuration, designed to be used with external mysql,
# mongo, rabbitmq, and elasticsearch services.

- name: Bootstrap instance(s)
  hosts: all
  gather_facts: no
  become: True
  roles:
    - python

- name: Configure instance(s)
  hosts: all
  become: True
  gather_facts: True

  vars:
    migrate_db: 'yes'
    openid_workaround: True
    EDXAPP_LMS_NGINX_PORT: '80'
    ENABLE_ECOMMERCE: False  # Disable ecommerce by default
  roles:

    # Ensure we have no known security vulnerabilities
    - security

    # Server setup
    - swapfile

    # Nginx reverse proxy
    - role: nginx
      nginx_sites:
      - certs
      - cms
      - lms
      - forum
      - xqueue
      nginx_default_sites:
      - lms

    # Main EdX application
    # https://github.com/edx/edx-platform
    - role: edxapp
      celery_worker: True
    - edxapp

    # Discussion forums
    # https://github.com/edx/cs_comments_service
    - forum

    # Notifications service
    # https://github.com/edx/notifier
    - role: notifier
      NOTIFIER_DIGEST_TASK_INTERVAL: '5'

    # XQueue interface for communicating with external grader services
    # https://github.com/edx/xqueue
    - role: xqueue
      update_users: True

    # Certificate generation
    # https://github.com/edx/edx-certificates
    - certs

    # Email sending
    - postfix_queue

    # Ecommerce (optional)
    # https://github.com/edx/ecommerce
    - role: nginx
      nginx_sites:
      - ecommerce
      when: ENABLE_ECOMMERCE
    - role: ecommerce
      when: ENABLE_ECOMMERCE
    - role: ecomworker
      when: ENABLE_ECOMMERCE

    # memcached
    - role: memcache
      when: "'localhost' in ' '.join(EDXAPP_MEMCACHE)"

    # Optional extras
    - role: datadog
      when: COMMON_ENABLE_DATADOG
    - role: splunkforwarder
      when: COMMON_ENABLE_SPLUNKFORWARDER
    - role: datadog-uninstall
      when: not COMMON_ENABLE_DATADOG