<commit_before>- name: setup the edxapp env
  template: >
    src=edxapp_env.j2 dest={{ edxapp_app_dir }}/edxapp_env
    owner={{ edxapp_user }}  group={{ common_web_user }}
    mode=0644
  tags:
    - install
    - install:configuration

- name: create edxapp configuration dir
  file: >
    path="{{ EDXAPP_CFG_DIR }}" state=directory
    owner="{{ edxapp_user }}" group="{{ common_web_group }}"
  tags:
    - install
    - install:configuration

- name: setup the newrelic python agent config
  template:
    src: "newrelic.ini.j2"
    dest: "{{ edxapp_app_dir }}/newrelic.ini"
    owner: "{{ edxapp_user }}"
    group: "{{ common_web_user }}"
    mode: "0644"
  tags:
    - install
    - install:configuration

# Optional auth for git
- name: create ssh script for git (not authenticated)
  template: >
    src=git_ssh_noauth.sh.j2 dest={{ edxapp_git_ssh }}
    owner={{ edxapp_user }} mode=750
  when: not EDXAPP_USE_GIT_IDENTITY
  tags:
    - install
    - install:base

- name: create ssh script for git (authenticated)
  template: >
    src=git_ssh_auth.sh.j2 dest={{ edxapp_git_ssh }}
    owner={{ edxapp_user }} mode=750
  when: EDXAPP_USE_GIT_IDENTITY
  tags:
    - install
    - install:base

- name: install read-only ssh key
  copy: >
    content="{{ EDXAPP_GIT_IDENTITY }}" dest={{ edxapp_git_identity }}
    force=yes owner={{ edxapp_user }} mode=0600
  when: EDXAPP_USE_GIT_IDENTITY
  tags:
    - install
    - install:base

- name: set git fetch.prune to ignore deleted remote refs
  shell: git config --global fetch.prune true
  sudo_user: "{{ edxapp_user }}"
  tags:
    - install
    - install:base

# Do A Checkout
- name: checkout edx-platform repo into {{ edxapp_code_dir }}
  git: >
    dest={{ edxapp_code_dir }}
    repo={{ edx_platform_repo }}
    version={{ edx_platform_version }}
    accept_hostkey=yes
  sudo_user: "{{ edxapp_user }}"
  environment:
    GIT_SSH: "{{ edxapp_git_ssh }}"
  register: edxapp_platform_checkout
  tags:
    - install
    - install:code

- name: git clean after checking out edx-platform
  shell: cd {{ edxapp_code_dir }} && git clean -xdf
  sudo_user: "{{ edxapp_user }}"
  tags:
    - install
    - install:code

# edX supports two theme types, Comprehensive themes and the older
# Stanford-style themes. They are mutually exclusive.
#
# To enable Stanford theming, point edxapp_theme_source_repo
# (yes, lowercase) to a Stanford-style theme and set
# edxapp_theme_name (again, lowercase) to its name.
- name: checkout Stanford-style theme
  git: >
    dest={{ edxapp_app_dir }}/themes/{{ edxapp_theme_name }}
    repo={{ edxapp_theme_source_repo }}
    version={{ edxapp_theme_version }}
    accept_hostkey=yes
  when: edxapp_theme_name != ''
  sudo_user: "{{ edxapp_user }}"
  environment:
    GIT_SSH: "{{ edxapp_git_ssh }}"
  register: edxapp_theme_checkout
  tags:
    - install
    - install:code

# To enable Comprehensive theming, point
# EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO to your theme repo, and set
# EDXAPP_COMPREHENSIVE_THEME_DIR to the directory you want to check
# out to.
- name: checkout comprehensive theme
  git: >
    dest={{ EDXAPP_COMPREHENSIVE_THEME_DIR }}
    repo={{ EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO }}
    version={{ EDXAPP_COMPREHENSIVE_THEME_VERSION }}
    accept_hostkey=yes
  when: EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO != ''
  sudo_user: "{{ edxapp_user }}"
  environment:
    GIT_SSH: "{{ edxapp_git_ssh }}"
  register: edxapp_theme_checkout
  tags:
    - install
    - install:code

- name: Stat each requirements file with Github URLs to ensure it exists
  stat: path="{{ item }}"
  with_items: "{{ edxapp_requirements_with_github_urls }}"
  register: requirement_file_stats
  tags:
    - install
    - install:code
    - install:app-requirements

# Substitute github mirror in all requirements files
# This is run on every single deploy
- name: Updating requirement files for git mirror
  command: |
    /bin/sed -i -e 's/github\.com/{{ COMMON_GIT_MIRROR }}/g' {{ item.item }}
  sudo_user: "{{ edxapp_user }}"
  when: item.stat.exists
  with_items: "{{ requirement_file_stats.results }}"
  tags:
    - install
    - install:code
    - install:app-requirements

# Set the npm registry
# This needs to be done as root since npm is weird about
# chown - https://github.com/npm/npm/issues/3565
- name: Set the npm registry
  shell:
    npm config set registry '{{ COMMON_NPM_MIRROR_URL }}'
    creates="{{ edxapp_app_dir }}/.npmrc"
  environment: "{{ edxapp_environment }}"
  tags:
    - install
    - install:app-requirements

# Set the npm registry permissions
- name: Set the npm registry permissions
  file:
    path="{{ edxapp_app_dir }}/.npmrc"
    owner=edxapp group=edxapp
  tags:
    - install
    - install:app-requirements

# Node play that need to be run after platform updates.
- name: Install edx-platform npm dependencies
  shell: npm install chdir={{ edxapp_code_dir }}
  sudo_user: "{{ edxapp_user }}"
  environment: "{{ edxapp_environment }}"
  tags:
    - install
    - install:app-requirements

- name: Create the virtualenv to install the Python requirements
  command: >
    virtualenv {{ edxapp_venv_dir }}
    chdir={{ edxapp_code_dir }}
    creates={{ edxapp_venv_dir }}/bin/pip
  sudo_user: "{{ edxapp_user }}"
  environment: "{{ edxapp_environment }}"
  tags:
    - install
    - install:app-requirements

- name: Stat each Python requirements file to ensure it exists
  stat: path="{{ item }}"
  with_items: "{{ edxapp_requirements_files }}"
  register: python_requirement_files
  tags:
    - install
    - install:app-requirements

# Install the python requirements into {{ edxapp_venv_dir }}
- name : install python requirements
  # Need to use command rather than pip so that we can maintain the context of our current working directory; some
  # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
  # installs everything into that virtual environment.
  command: >
    {{ edxapp_venv_dir }}/bin/pip install {{ COMMON_PIP_VERBOSITY }} -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item.item }}
    chdir={{ edxapp_code_dir }}
  sudo_user: "{{ edxapp_user }}"
  environment: "{{ edxapp_environment }}"
  when: item.stat.exists
  with_items: "{{ python_requirement_files.results }}"
  tags:
    - install
    - install:app-requirements

# Private requriements require a ssh key to install, use the same key as the private key for edx-platform
# If EDXAPP_INSTALL_PRIVATE_REQUIREMENTS is set to true EDXAPP_USE_GIT_IDENTITY must also be true
- name : install python private requirements
  # Need to use shell rather than pip so that we can maintain the context of our current working directory; some
  # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
  # installs everything into that virtual environment.
  shell: >
    {{ edxapp_venv_dir }}/bin/pip install {{ COMMON_PIP_VERBOSITY }} -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item }}
    chdir={{ edxapp_code_dir }}
  with_items:
  - "{{ private_requirements_file }}"
  sudo_user: "{{ edxapp_user }}"
  environment:
    GIT_SSH: "{{ edxapp_git_ssh }}"
  when: EDXAPP_INSTALL_PRIVATE_REQUIREMENTS
  tags:
    - install
    - install:app-requirements

# Install any custom extra requirements if defined in EDXAPP_EXTRA_REQUIREMENTS.
- name: install python extra requirements
  pip: >
    name="{{ item.name }}"
    version="{{ item.version|default(omit) }}"
    extra_args="--exists-action w {{ item.extra_args|default('') }}"
    virtualenv="{{ edxapp_venv_dir }}"
    state=present
  with_items: EDXAPP_EXTRA_REQUIREMENTS
  sudo_user: "{{ edxapp_user }}"
  tags:
    - install
    - install:app-requirements

# If using CAS and you have a function for mapping attributes, install
# the module here.  The next few tasks set up the python code sandbox
- name: install CAS attribute module
  pip: >
    name="{{ EDXAPP_CAS_ATTRIBUTE_PACKAGE }}"
    virtualenv="{{ edxapp_venv_dir }}"
    state=present
    extra_args="-i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w"
  sudo_user: "{{ edxapp_user }}"
  when: EDXAPP_CAS_ATTRIBUTE_PACKAGE|length > 0
  tags:
    - install
    - install:app-requirements

# Install the sandbox python modules into {{ edxapp_venv_dir }}
- name : install sandbox requirements into regular venv
  # Need to use shell rather than pip so that we can maintain the context of our current working directory; some
  # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
  # installs everything into that virtual environment.
  shell: >
    {{ edxapp_venv_dir }}/bin/pip install {{ COMMON_PIP_VERBOSITY }} -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item }}
    chdir={{ edxapp_code_dir }}
  with_items:
  - "{{ sandbox_base_requirements }}"
  - "{{ sandbox_local_requirements }}"
  - "{{ sandbox_post_requirements }}"
  sudo_user: "{{ edxapp_user }}"
  when: not EDXAPP_PYTHON_SANDBOX
  tags:
    - install
    - install:app-requirements

# The next few tasks set up the python code sandbox

# need to disable this profile, otherwise the pip inside the sandbox venv has no permissions
# to install anything
- name: code sandbox | put sandbox apparmor profile in complain mode
  command: /usr/sbin/aa-complain /etc/apparmor.d/code.sandbox
  when: EDXAPP_PYTHON_SANDBOX
  tags:
  - edxapp-sandbox
  - install
  - install:app-requirements

- name: code sandbox | Install base sandbox requirements and create sandbox virtualenv
  pip: >
    requirements="{{ sandbox_base_requirements }}"
    virtualenv="{{ edxapp_sandbox_venv_dir }}"
    state=present
    extra_args="-i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w"
  sudo_user: "{{ edxapp_sandbox_user }}"
  when: EDXAPP_PYTHON_SANDBOX
  tags:
  - edxapp-sandbox
  - install
  - install:app-requirements

- name: code sandbox | Install sandbox requirements into sandbox venv
  shell: >
    {{ edxapp_sandbox_venv_dir }}/bin/pip install -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item }}
    chdir={{ edxapp_code_dir }}
  with_items:
  - "{{ sandbox_local_requirements }}"
  - "{{ sandbox_post_requirements }}"
  sudo_user: "{{ edxapp_sandbox_user }}"
  when: EDXAPP_PYTHON_SANDBOX
  register: sandbox_install_output
  changed_when: sandbox_install_output.stdout is defined and 'installed' in sandbox_install_output.stdout
  tags:
  - edxapp-sandbox
  - install
  - install:app-requirements

- name: code sandbox | put code sandbox into aa-enforce or aa-complain mode, depending on EDXAPP_SANDBOX_ENFORCE
  command: /usr/sbin/{{ edxapp_aa_command }} /etc/apparmor.d/code.sandbox
  when: EDXAPP_PYTHON_SANDBOX
  tags:
  - edxapp-sandbox
  - install
  - install:app-requirements

- name: compiling all py files in the edx-platform repo
  shell: "{{ edxapp_venv_bin }}/python -m compileall -x .git/.* {{ edxapp_code_dir }}"
  sudo_user: "{{ edxapp_user }}"
  tags:
    - install
    - install:code

  # alternative would be to give {{ common_web_user }} read access
  # to the virtualenv but that permission change will require
  # root access.
- name: give other read permissions to the virtualenv
  command: chmod -R o+r "{{ edxapp_venv_dir }}"
  tags:
    - install
    - install:code

# creates the supervisor jobs for the
# service variants configured, runs
# gather_assets and db migrations
- include: service_variant_config.yml
  tags:
    - service_variant_config
    - deploy

  # call supervisorctl update. this reloads
  # the supervisorctl config and restarts
  # the services if any of the configurations
  # have changed.

- name: update supervisor configuration
  shell:  "{{ supervisor_ctl }} -c {{ supervisor_cfg }} update"
  register: supervisor_update
  sudo_user: "{{ supervisor_service_user }}"
  changed_when: supervisor_update.stdout is defined and supervisor_update.stdout != ""
  when: not disable_edx_services
  tags:
    - manage

- name: ensure edxapp has started
  supervisorctl: >
    state=started
    supervisorctl_path={{ supervisor_ctl }}
    config={{ supervisor_cfg }}
    name="edxapp:"
  sudo_user: "{{ supervisor_service_user }}"
  when: celery_worker is not defined and not disable_edx_services
  tags:
    - manage

- name: ensure edxapp_workers has started
  supervisorctl: >
    name="edxapp_worker:"
    supervisorctl_path={{ supervisor_ctl }}
    config={{ supervisor_cfg }}
    state=started
  when: celery_worker is defined and not disable_edx_services
  sudo_user: "{{ supervisor_service_user }}"
  tags:
    - manage

- name: create symlinks from the venv bin dir
  file: >
    src="{{ edxapp_venv_bin }}/{{ item }}"
    dest={{ COMMON_BIN_DIR }}/{{ item.split('.')[0] }}.edxapp
    state=link
  with_items:
  - python
  - pip
  - django-admin.py
  tags:
    - install
    - install:configuration

- name: create symlinks from the repo dir
  file: >
    src="{{ edxapp_code_dir }}/{{ item }}"
    dest={{ COMMON_BIN_DIR }}/{{ item.split('.')[0] }}.edxapp
    state=link
  with_items:
  - manage.py
  tags:
    - install
    - install:configuration

- name: remove read-only ssh key
  file: path={{ edxapp_git_identity }} state=absent
  when: EDXAPP_USE_GIT_IDENTITY
  tags:
    - install
    - install:configuration
    - install:code

- include: tag_ec2.yml tags=deploy
  when: COMMON_TAG_EC2_INSTANCE
  tags:
    - remove
    - aws

- set_fact: edxapp_installed=true

- name: restart edxapp
  supervisorctl: >
    state=restarted
    supervisorctl_path={{ supervisor_ctl }}
    config={{ supervisor_cfg }}
    name="edxapp:"
  when: edxapp_installed is defined and celery_worker is not defined and not disable_edx_services
  sudo_user: "{{ supervisor_service_user }}"
  tags:
    - manage

- name: restart edxapp_workers
  supervisorctl: >
    name="edxapp_worker:"
    supervisorctl_path={{ supervisor_ctl }}
    config={{ supervisor_cfg }}
    state=restarted
  when: edxapp_installed is defined and celery_worker is defined and not disable_edx_services
  sudo_user: "{{ common_web_user }}"
  tags:
    - manage
<commit_msg>This registers over the microsites theming<commit_after>- name: setup the edxapp env
  template: >
    src=edxapp_env.j2 dest={{ edxapp_app_dir }}/edxapp_env
    owner={{ edxapp_user }}  group={{ common_web_user }}
    mode=0644
  tags:
    - install
    - install:configuration

- name: create edxapp configuration dir
  file: >
    path="{{ EDXAPP_CFG_DIR }}" state=directory
    owner="{{ edxapp_user }}" group="{{ common_web_group }}"
  tags:
    - install
    - install:configuration

- name: setup the newrelic python agent config
  template:
    src: "newrelic.ini.j2"
    dest: "{{ edxapp_app_dir }}/newrelic.ini"
    owner: "{{ edxapp_user }}"
    group: "{{ common_web_user }}"
    mode: "0644"
  tags:
    - install
    - install:configuration

# Optional auth for git
- name: create ssh script for git (not authenticated)
  template: >
    src=git_ssh_noauth.sh.j2 dest={{ edxapp_git_ssh }}
    owner={{ edxapp_user }} mode=750
  when: not EDXAPP_USE_GIT_IDENTITY
  tags:
    - install
    - install:base

- name: create ssh script for git (authenticated)
  template: >
    src=git_ssh_auth.sh.j2 dest={{ edxapp_git_ssh }}
    owner={{ edxapp_user }} mode=750
  when: EDXAPP_USE_GIT_IDENTITY
  tags:
    - install
    - install:base

- name: install read-only ssh key
  copy: >
    content="{{ EDXAPP_GIT_IDENTITY }}" dest={{ edxapp_git_identity }}
    force=yes owner={{ edxapp_user }} mode=0600
  when: EDXAPP_USE_GIT_IDENTITY
  tags:
    - install
    - install:base

- name: set git fetch.prune to ignore deleted remote refs
  shell: git config --global fetch.prune true
  sudo_user: "{{ edxapp_user }}"
  tags:
    - install
    - install:base

# Do A Checkout
- name: checkout edx-platform repo into {{ edxapp_code_dir }}
  git: >
    dest={{ edxapp_code_dir }}
    repo={{ edx_platform_repo }}
    version={{ edx_platform_version }}
    accept_hostkey=yes
  sudo_user: "{{ edxapp_user }}"
  environment:
    GIT_SSH: "{{ edxapp_git_ssh }}"
  register: edxapp_platform_checkout
  tags:
    - install
    - install:code

- name: git clean after checking out edx-platform
  shell: cd {{ edxapp_code_dir }} && git clean -xdf
  sudo_user: "{{ edxapp_user }}"
  tags:
    - install
    - install:code

# edX supports two theme types, Comprehensive themes and the older
# Stanford-style themes. They are mutually exclusive.
#
# To enable Stanford theming, point edxapp_theme_source_repo
# (yes, lowercase) to a Stanford-style theme and set
# edxapp_theme_name (again, lowercase) to its name.
- name: checkout Stanford-style theme
  git: >
    dest={{ edxapp_app_dir }}/themes/{{ edxapp_theme_name }}
    repo={{ edxapp_theme_source_repo }}
    version={{ edxapp_theme_version }}
    accept_hostkey=yes
  when: edxapp_theme_name != ''
  sudo_user: "{{ edxapp_user }}"
  environment:
    GIT_SSH: "{{ edxapp_git_ssh }}"
  register: edxapp_theme_checkout
  tags:
    - install
    - install:code

# To enable Comprehensive theming, point
# EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO to your theme repo, and set
# EDXAPP_COMPREHENSIVE_THEME_DIR to the directory you want to check
# out to.
- name: checkout comprehensive theme
  git: >
    dest={{ EDXAPP_COMPREHENSIVE_THEME_DIR }}
    repo={{ EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO }}
    version={{ EDXAPP_COMPREHENSIVE_THEME_VERSION }}
    accept_hostkey=yes
  when: EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO != ''
  sudo_user: "{{ edxapp_user }}"
  environment:
    GIT_SSH: "{{ edxapp_git_ssh }}"
  register: edxapp_comprehensive_theme_checkout
  tags:
    - install
    - install:code

- name: Stat each requirements file with Github URLs to ensure it exists
  stat: path="{{ item }}"
  with_items: "{{ edxapp_requirements_with_github_urls }}"
  register: requirement_file_stats
  tags:
    - install
    - install:code
    - install:app-requirements

# Substitute github mirror in all requirements files
# This is run on every single deploy
- name: Updating requirement files for git mirror
  command: |
    /bin/sed -i -e 's/github\.com/{{ COMMON_GIT_MIRROR }}/g' {{ item.item }}
  sudo_user: "{{ edxapp_user }}"
  when: item.stat.exists
  with_items: "{{ requirement_file_stats.results }}"
  tags:
    - install
    - install:code
    - install:app-requirements

# Set the npm registry
# This needs to be done as root since npm is weird about
# chown - https://github.com/npm/npm/issues/3565
- name: Set the npm registry
  shell:
    npm config set registry '{{ COMMON_NPM_MIRROR_URL }}'
    creates="{{ edxapp_app_dir }}/.npmrc"
  environment: "{{ edxapp_environment }}"
  tags:
    - install
    - install:app-requirements

# Set the npm registry permissions
- name: Set the npm registry permissions
  file:
    path="{{ edxapp_app_dir }}/.npmrc"
    owner=edxapp group=edxapp
  tags:
    - install
    - install:app-requirements

# Node play that need to be run after platform updates.
- name: Install edx-platform npm dependencies
  shell: npm install chdir={{ edxapp_code_dir }}
  sudo_user: "{{ edxapp_user }}"
  environment: "{{ edxapp_environment }}"
  tags:
    - install
    - install:app-requirements

- name: Create the virtualenv to install the Python requirements
  command: >
    virtualenv {{ edxapp_venv_dir }}
    chdir={{ edxapp_code_dir }}
    creates={{ edxapp_venv_dir }}/bin/pip
  sudo_user: "{{ edxapp_user }}"
  environment: "{{ edxapp_environment }}"
  tags:
    - install
    - install:app-requirements

- name: Stat each Python requirements file to ensure it exists
  stat: path="{{ item }}"
  with_items: "{{ edxapp_requirements_files }}"
  register: python_requirement_files
  tags:
    - install
    - install:app-requirements

# Install the python requirements into {{ edxapp_venv_dir }}
- name : install python requirements
  # Need to use command rather than pip so that we can maintain the context of our current working directory; some
  # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
  # installs everything into that virtual environment.
  command: >
    {{ edxapp_venv_dir }}/bin/pip install {{ COMMON_PIP_VERBOSITY }} -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item.item }}
    chdir={{ edxapp_code_dir }}
  sudo_user: "{{ edxapp_user }}"
  environment: "{{ edxapp_environment }}"
  when: item.stat.exists
  with_items: "{{ python_requirement_files.results }}"
  tags:
    - install
    - install:app-requirements

# Private requriements require a ssh key to install, use the same key as the private key for edx-platform
# If EDXAPP_INSTALL_PRIVATE_REQUIREMENTS is set to true EDXAPP_USE_GIT_IDENTITY must also be true
- name : install python private requirements
  # Need to use shell rather than pip so that we can maintain the context of our current working directory; some
  # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
  # installs everything into that virtual environment.
  shell: >
    {{ edxapp_venv_dir }}/bin/pip install {{ COMMON_PIP_VERBOSITY }} -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item }}
    chdir={{ edxapp_code_dir }}
  with_items:
  - "{{ private_requirements_file }}"
  sudo_user: "{{ edxapp_user }}"
  environment:
    GIT_SSH: "{{ edxapp_git_ssh }}"
  when: EDXAPP_INSTALL_PRIVATE_REQUIREMENTS
  tags:
    - install
    - install:app-requirements

# Install any custom extra requirements if defined in EDXAPP_EXTRA_REQUIREMENTS.
- name: install python extra requirements
  pip: >
    name="{{ item.name }}"
    version="{{ item.version|default(omit) }}"
    extra_args="--exists-action w {{ item.extra_args|default('') }}"
    virtualenv="{{ edxapp_venv_dir }}"
    state=present
  with_items: EDXAPP_EXTRA_REQUIREMENTS
  sudo_user: "{{ edxapp_user }}"
  tags:
    - install
    - install:app-requirements

# If using CAS and you have a function for mapping attributes, install
# the module here.  The next few tasks set up the python code sandbox
- name: install CAS attribute module
  pip: >
    name="{{ EDXAPP_CAS_ATTRIBUTE_PACKAGE }}"
    virtualenv="{{ edxapp_venv_dir }}"
    state=present
    extra_args="-i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w"
  sudo_user: "{{ edxapp_user }}"
  when: EDXAPP_CAS_ATTRIBUTE_PACKAGE|length > 0
  tags:
    - install
    - install:app-requirements

# Install the sandbox python modules into {{ edxapp_venv_dir }}
- name : install sandbox requirements into regular venv
  # Need to use shell rather than pip so that we can maintain the context of our current working directory; some
  # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
  # installs everything into that virtual environment.
  shell: >
    {{ edxapp_venv_dir }}/bin/pip install {{ COMMON_PIP_VERBOSITY }} -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item }}
    chdir={{ edxapp_code_dir }}
  with_items:
  - "{{ sandbox_base_requirements }}"
  - "{{ sandbox_local_requirements }}"
  - "{{ sandbox_post_requirements }}"
  sudo_user: "{{ edxapp_user }}"
  when: not EDXAPP_PYTHON_SANDBOX
  tags:
    - install
    - install:app-requirements

# The next few tasks set up the python code sandbox

# need to disable this profile, otherwise the pip inside the sandbox venv has no permissions
# to install anything
- name: code sandbox | put sandbox apparmor profile in complain mode
  command: /usr/sbin/aa-complain /etc/apparmor.d/code.sandbox
  when: EDXAPP_PYTHON_SANDBOX
  tags:
  - edxapp-sandbox
  - install
  - install:app-requirements

- name: code sandbox | Install base sandbox requirements and create sandbox virtualenv
  pip: >
    requirements="{{ sandbox_base_requirements }}"
    virtualenv="{{ edxapp_sandbox_venv_dir }}"
    state=present
    extra_args="-i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w"
  sudo_user: "{{ edxapp_sandbox_user }}"
  when: EDXAPP_PYTHON_SANDBOX
  tags:
  - edxapp-sandbox
  - install
  - install:app-requirements

- name: code sandbox | Install sandbox requirements into sandbox venv
  shell: >
    {{ edxapp_sandbox_venv_dir }}/bin/pip install -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item }}
    chdir={{ edxapp_code_dir }}
  with_items:
  - "{{ sandbox_local_requirements }}"
  - "{{ sandbox_post_requirements }}"
  sudo_user: "{{ edxapp_sandbox_user }}"
  when: EDXAPP_PYTHON_SANDBOX
  register: sandbox_install_output
  changed_when: sandbox_install_output.stdout is defined and 'installed' in sandbox_install_output.stdout
  tags:
  - edxapp-sandbox
  - install
  - install:app-requirements

- name: code sandbox | put code sandbox into aa-enforce or aa-complain mode, depending on EDXAPP_SANDBOX_ENFORCE
  command: /usr/sbin/{{ edxapp_aa_command }} /etc/apparmor.d/code.sandbox
  when: EDXAPP_PYTHON_SANDBOX
  tags:
  - edxapp-sandbox
  - install
  - install:app-requirements

- name: compiling all py files in the edx-platform repo
  shell: "{{ edxapp_venv_bin }}/python -m compileall -x .git/.* {{ edxapp_code_dir }}"
  sudo_user: "{{ edxapp_user }}"
  tags:
    - install
    - install:code

  # alternative would be to give {{ common_web_user }} read access
  # to the virtualenv but that permission change will require
  # root access.
- name: give other read permissions to the virtualenv
  command: chmod -R o+r "{{ edxapp_venv_dir }}"
  tags:
    - install
    - install:code

# creates the supervisor jobs for the
# service variants configured, runs
# gather_assets and db migrations
- include: service_variant_config.yml
  tags:
    - service_variant_config
    - deploy

  # call supervisorctl update. this reloads
  # the supervisorctl config and restarts
  # the services if any of the configurations
  # have changed.

- name: update supervisor configuration
  shell:  "{{ supervisor_ctl }} -c {{ supervisor_cfg }} update"
  register: supervisor_update
  sudo_user: "{{ supervisor_service_user }}"
  changed_when: supervisor_update.stdout is defined and supervisor_update.stdout != ""
  when: not disable_edx_services
  tags:
    - manage

- name: ensure edxapp has started
  supervisorctl: >
    state=started
    supervisorctl_path={{ supervisor_ctl }}
    config={{ supervisor_cfg }}
    name="edxapp:"
  sudo_user: "{{ supervisor_service_user }}"
  when: celery_worker is not defined and not disable_edx_services
  tags:
    - manage

- name: ensure edxapp_workers has started
  supervisorctl: >
    name="edxapp_worker:"
    supervisorctl_path={{ supervisor_ctl }}
    config={{ supervisor_cfg }}
    state=started
  when: celery_worker is defined and not disable_edx_services
  sudo_user: "{{ supervisor_service_user }}"
  tags:
    - manage

- name: create symlinks from the venv bin dir
  file: >
    src="{{ edxapp_venv_bin }}/{{ item }}"
    dest={{ COMMON_BIN_DIR }}/{{ item.split('.')[0] }}.edxapp
    state=link
  with_items:
  - python
  - pip
  - django-admin.py
  tags:
    - install
    - install:configuration

- name: create symlinks from the repo dir
  file: >
    src="{{ edxapp_code_dir }}/{{ item }}"
    dest={{ COMMON_BIN_DIR }}/{{ item.split('.')[0] }}.edxapp
    state=link
  with_items:
  - manage.py
  tags:
    - install
    - install:configuration

- name: remove read-only ssh key
  file: path={{ edxapp_git_identity }} state=absent
  when: EDXAPP_USE_GIT_IDENTITY
  tags:
    - install
    - install:configuration
    - install:code

- include: tag_ec2.yml tags=deploy
  when: COMMON_TAG_EC2_INSTANCE
  tags:
    - remove
    - aws

- set_fact: edxapp_installed=true

- name: restart edxapp
  supervisorctl: >
    state=restarted
    supervisorctl_path={{ supervisor_ctl }}
    config={{ supervisor_cfg }}
    name="edxapp:"
  when: edxapp_installed is defined and celery_worker is not defined and not disable_edx_services
  sudo_user: "{{ supervisor_service_user }}"
  tags:
    - manage

- name: restart edxapp_workers
  supervisorctl: >
    name="edxapp_worker:"
    supervisorctl_path={{ supervisor_ctl }}
    config={{ supervisor_cfg }}
    state=restarted
  when: edxapp_installed is defined and celery_worker is defined and not disable_edx_services
  sudo_user: "{{ common_web_user }}"
  tags:
    - manage

{'fraction_non_alphanumeric': 0.10299486088959774, 'fraction_numerical': 0.002197412723728513, 'mean_word_length': 3.7136652188439694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6425138', 'n_tokens_mistral': 9648, 'n_tokens_neox': 9413, 'n_words': 2511}