Commit a7837987 by arbabnazar

rewrite the edxapp role

parent 73545e9a
- 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 - name: create edxapp configuration dir
file: > file:
path="{{ EDXAPP_CFG_DIR }}" state=directory path: "{{ EDXAPP_CFG_DIR }}"
owner="{{ edxapp_user }}" group="{{ common_web_group }}" state: directory
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 }}" owner: "{{ edxapp_user }}"
group: "{{ common_web_user }}" group: "{{ common_web_group }}"
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: tags:
- install - install
- install:base - install:base
- name: create ssh script for git (authenticated) - name: copy the template to the desired location
template: > template:
src=git_ssh_auth.sh.j2 dest={{ edxapp_git_ssh }} src: "{{ item.src }}"
owner={{ edxapp_user }} mode=750 dest: "{{ item.dest }}"
when: EDXAPP_USE_GIT_IDENTITY owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "0644"
with_items:
- { src: 'edxapp_env.j2', dest: '{{ edxapp_app_dir }}/edxapp_env', owner: '{{ edxapp_user }}', group: '{{ common_web_user }}' }
- { src: 'newrelic.ini.j2', dest: '{{ edxapp_app_dir }}/newrelic.ini', owner: '{{ edxapp_user }}', group: '{{ common_web_user }}' }
- { src: 'git_ssh.sh.j2', dest: '{{ edxapp_git_ssh }}', owner: '{{ edxapp_user }}', group: '{{ edxapp_user }}' }
tags: tags:
- install - install
- install:base - install:base
- name: install read-only ssh key - name: install read-only ssh key
copy: > copy:
content="{{ EDXAPP_GIT_IDENTITY }}" dest={{ edxapp_git_identity }} content: "{{ EDXAPP_GIT_IDENTITY }}"
force=yes owner={{ edxapp_user }} mode=0600 dest: "{{ edxapp_git_identity }}"
force: yes
owner: "{{ edxapp_user }}"
mode: "0600"
when: EDXAPP_USE_GIT_IDENTITY when: EDXAPP_USE_GIT_IDENTITY
tags: tags:
- install - install
...@@ -63,11 +45,11 @@ ...@@ -63,11 +45,11 @@
# Do A Checkout # Do A Checkout
- name: checkout edx-platform repo into {{ edxapp_code_dir }} - name: checkout edx-platform repo into {{ edxapp_code_dir }}
git_2_0_1: > git_2_0_1:
dest={{ edxapp_code_dir }} dest: "{{ edxapp_code_dir }}"
repo={{ edx_platform_repo }} repo: "{{ edx_platform_repo }}"
version={{ edx_platform_version }} version: "{{ edx_platform_version }}"
accept_hostkey=yes accept_hostkey: yes
sudo_user: "{{ edxapp_user }}" sudo_user: "{{ edxapp_user }}"
environment: environment:
GIT_SSH: "{{ edxapp_git_ssh }}" GIT_SSH: "{{ edxapp_git_ssh }}"
...@@ -90,11 +72,11 @@ ...@@ -90,11 +72,11 @@
# (yes, lowercase) to a Stanford-style theme and set # (yes, lowercase) to a Stanford-style theme and set
# edxapp_theme_name (again, lowercase) to its name. # edxapp_theme_name (again, lowercase) to its name.
- name: checkout Stanford-style theme - name: checkout Stanford-style theme
git_2_0_1: > git_2_0_1:
dest={{ edxapp_app_dir }}/themes/{{ edxapp_theme_name }} dest: "{{ edxapp_app_dir }}/themes/{{ edxapp_theme_name }}"
repo={{ edxapp_theme_source_repo }} repo: "{{ edxapp_theme_source_repo }}"
version={{ edxapp_theme_version }} version: "{{ edxapp_theme_version }}"
accept_hostkey=yes accept_hostkey: yes
when: edxapp_theme_name != '' when: edxapp_theme_name != ''
sudo_user: "{{ edxapp_user }}" sudo_user: "{{ edxapp_user }}"
environment: environment:
...@@ -109,11 +91,11 @@ ...@@ -109,11 +91,11 @@
# EDXAPP_COMPREHENSIVE_THEME_DIR to the directory you want to check # EDXAPP_COMPREHENSIVE_THEME_DIR to the directory you want to check
# out to. # out to.
- name: checkout comprehensive theme - name: checkout comprehensive theme
git_2_0_1: > git_2_0_1:
dest={{ EDXAPP_COMPREHENSIVE_THEME_DIR }} dest: "{{ EDXAPP_COMPREHENSIVE_THEME_DIR }}"
repo={{ EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO }} repo: "{{ EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO }}"
version={{ EDXAPP_COMPREHENSIVE_THEME_VERSION }} version: "{{ EDXAPP_COMPREHENSIVE_THEME_VERSION }}"
accept_hostkey=yes accept_hostkey: yes
when: EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO != '' when: EDXAPP_COMPREHENSIVE_THEME_SOURCE_REPO != ''
sudo_user: "{{ edxapp_user }}" sudo_user: "{{ edxapp_user }}"
environment: environment:
...@@ -124,7 +106,8 @@ ...@@ -124,7 +106,8 @@
- install:code - install:code
- name: Stat each requirements file with Github URLs to ensure it exists - name: Stat each requirements file with Github URLs to ensure it exists
stat: path="{{ item }}" stat:
path: "{{ item }}"
with_items: "{{ edxapp_requirements_with_github_urls }}" with_items: "{{ edxapp_requirements_with_github_urls }}"
register: requirement_file_stats register: requirement_file_stats
tags: tags:
...@@ -160,8 +143,9 @@ ...@@ -160,8 +143,9 @@
# Set the npm registry permissions # Set the npm registry permissions
- name: Set the npm registry permissions - name: Set the npm registry permissions
file: file:
path="{{ edxapp_app_dir }}/.npmrc" path: "{{ edxapp_app_dir }}/.npmrc"
owner=edxapp group=edxapp owner: "{{ edxapp_user }}"
group: "{{ edxapp_user }}"
tags: tags:
- install - install
- install:app-requirements - install:app-requirements
...@@ -187,7 +171,8 @@ ...@@ -187,7 +171,8 @@
- install:app-requirements - install:app-requirements
- name: Stat each Python requirements file to ensure it exists - name: Stat each Python requirements file to ensure it exists
stat: path="{{ item }}" stat:
path: "{{ item }}"
with_items: "{{ edxapp_requirements_files }}" with_items: "{{ edxapp_requirements_files }}"
register: python_requirement_files register: python_requirement_files
tags: tags:
...@@ -195,7 +180,7 @@ ...@@ -195,7 +180,7 @@
- install:app-requirements - install:app-requirements
# Install the python requirements into {{ edxapp_venv_dir }} # Install the python requirements into {{ edxapp_venv_dir }}
- name : install python requirements - name: install python requirements
# Need to use command rather than pip so that we can maintain the context of our current working directory; some # 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 # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
# installs everything into that virtual environment. # installs everything into that virtual environment.
...@@ -212,7 +197,7 @@ ...@@ -212,7 +197,7 @@
# Private requriements require a ssh key to install, use the same key as the private key for edx-platform # 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 # If EDXAPP_INSTALL_PRIVATE_REQUIREMENTS is set to true EDXAPP_USE_GIT_IDENTITY must also be true
- name : install python private requirements - 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 # 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 # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
# installs everything into that virtual environment. # installs everything into that virtual environment.
...@@ -231,12 +216,12 @@ ...@@ -231,12 +216,12 @@
# Install any custom extra requirements if defined in EDXAPP_EXTRA_REQUIREMENTS. # Install any custom extra requirements if defined in EDXAPP_EXTRA_REQUIREMENTS.
- name: install python extra requirements - name: install python extra requirements
pip: > pip:
name="{{ item.name }}" name: "{{ item.name }}"
version="{{ item.version|default(omit) }}" version: "{{ item.version|default(omit) }}"
extra_args="--exists-action w {{ item.extra_args|default('') }}" extra_args: "--exists-action w {{ item.extra_args|default('') }}"
virtualenv="{{ edxapp_venv_dir }}" virtualenv: "{{ edxapp_venv_dir }}"
state=present state: present
with_items: EDXAPP_EXTRA_REQUIREMENTS with_items: EDXAPP_EXTRA_REQUIREMENTS
sudo_user: "{{ edxapp_user }}" sudo_user: "{{ edxapp_user }}"
tags: tags:
...@@ -246,11 +231,11 @@ ...@@ -246,11 +231,11 @@
# If using CAS and you have a function for mapping attributes, install # 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 # the module here. The next few tasks set up the python code sandbox
- name: install CAS attribute module - name: install CAS attribute module
pip: > pip:
name="{{ EDXAPP_CAS_ATTRIBUTE_PACKAGE }}" name: "{{ EDXAPP_CAS_ATTRIBUTE_PACKAGE }}"
virtualenv="{{ edxapp_venv_dir }}" virtualenv: "{{ edxapp_venv_dir }}"
state=present state: present
extra_args="-i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w" extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w"
sudo_user: "{{ edxapp_user }}" sudo_user: "{{ edxapp_user }}"
when: EDXAPP_CAS_ATTRIBUTE_PACKAGE|length > 0 when: EDXAPP_CAS_ATTRIBUTE_PACKAGE|length > 0
tags: tags:
...@@ -258,7 +243,7 @@ ...@@ -258,7 +243,7 @@
- install:app-requirements - install:app-requirements
# Install the sandbox python modules into {{ edxapp_venv_dir }} # Install the sandbox python modules into {{ edxapp_venv_dir }}
- name : install sandbox requirements into regular venv - 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 # 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 # requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
# installs everything into that virtual environment. # installs everything into that virtual environment.
...@@ -283,46 +268,46 @@ ...@@ -283,46 +268,46 @@
command: /usr/sbin/aa-complain /etc/apparmor.d/code.sandbox command: /usr/sbin/aa-complain /etc/apparmor.d/code.sandbox
when: EDXAPP_PYTHON_SANDBOX when: EDXAPP_PYTHON_SANDBOX
tags: tags:
- edxapp-sandbox - edxapp-sandbox
- install - install
- install:app-requirements - install:app-requirements
- name: code sandbox | Install base sandbox requirements and create sandbox virtualenv - name: code sandbox | Install base sandbox requirements and create sandbox virtualenv
pip: > pip:
requirements="{{ sandbox_base_requirements }}" requirements: "{{ sandbox_base_requirements }}"
virtualenv="{{ edxapp_sandbox_venv_dir }}" virtualenv: "{{ edxapp_sandbox_venv_dir }}"
state=present state: present
extra_args="-i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w" extra_args: "-i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w"
sudo_user: "{{ edxapp_sandbox_user }}" sudo_user: "{{ edxapp_sandbox_user }}"
when: EDXAPP_PYTHON_SANDBOX when: EDXAPP_PYTHON_SANDBOX
tags: tags:
- edxapp-sandbox - edxapp-sandbox
- install - install
- install:app-requirements - install:app-requirements
- name: code sandbox | Install sandbox requirements into sandbox venv - name: code sandbox | Install sandbox requirements into sandbox venv
shell: > shell: >
{{ edxapp_sandbox_venv_dir }}/bin/pip install -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item }} {{ edxapp_sandbox_venv_dir }}/bin/pip install -i {{ COMMON_PYPI_MIRROR_URL }} --exists-action w -r {{ item }}
chdir={{ edxapp_code_dir }} chdir={{ edxapp_code_dir }}
with_items: with_items:
- "{{ sandbox_local_requirements }}" - "{{ sandbox_local_requirements }}"
- "{{ sandbox_post_requirements }}" - "{{ sandbox_post_requirements }}"
sudo_user: "{{ edxapp_sandbox_user }}" sudo_user: "{{ edxapp_sandbox_user }}"
when: EDXAPP_PYTHON_SANDBOX when: EDXAPP_PYTHON_SANDBOX
register: sandbox_install_output register: sandbox_install_output
changed_when: sandbox_install_output.stdout is defined and 'installed' in sandbox_install_output.stdout changed_when: sandbox_install_output.stdout is defined and 'installed' in sandbox_install_output.stdout
tags: tags:
- edxapp-sandbox - edxapp-sandbox
- install - install
- install:app-requirements - install:app-requirements
- name: code sandbox | put code sandbox into aa-enforce or aa-complain mode, depending on EDXAPP_SANDBOX_ENFORCE - 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 command: /usr/sbin/{{ edxapp_aa_command }} /etc/apparmor.d/code.sandbox
when: EDXAPP_PYTHON_SANDBOX when: EDXAPP_PYTHON_SANDBOX
tags: tags:
- edxapp-sandbox - edxapp-sandbox
- install - install
- install:app-requirements - install:app-requirements
- name: compiling all py files in the edx-platform repo - name: compiling all py files in the edx-platform repo
shell: "{{ edxapp_venv_bin }}/python -m compileall -q -x .git/.* {{ edxapp_code_dir }}" shell: "{{ edxapp_venv_bin }}/python -m compileall -q -x .git/.* {{ edxapp_code_dir }}"
...@@ -335,7 +320,11 @@ ...@@ -335,7 +320,11 @@
# to the virtualenv but that permission change will require # to the virtualenv but that permission change will require
# root access. # root access.
- name: give other read permissions to the virtualenv - name: give other read permissions to the virtualenv
command: chmod -R o+r "{{ edxapp_venv_dir }}" file:
path: "{{ edxapp_venv_dir }}"
state: directory
mode: "o+r"
recurse: yes
tags: tags:
- install - install
- install:code - install:code
...@@ -363,53 +352,45 @@ ...@@ -363,53 +352,45 @@
- manage - manage
- name: ensure edxapp has started - name: ensure edxapp has started
supervisorctl: > supervisorctl:
state=started name: "edxapp:"
supervisorctl_path={{ supervisor_ctl }} supervisorctl_path: "{{ supervisor_ctl }}"
config={{ supervisor_cfg }} config: "{{ supervisor_cfg }}"
name="edxapp:" state: started
sudo_user: "{{ supervisor_service_user }}" sudo_user: "{{ supervisor_service_user }}"
when: celery_worker is not defined and not disable_edx_services when: celery_worker is not defined and not disable_edx_services
tags: tags:
- manage - manage
- name: ensure edxapp_workers has started - name: ensure edxapp_workers has started
supervisorctl: > supervisorctl:
name="edxapp_worker:" name: "edxapp_worker:"
supervisorctl_path={{ supervisor_ctl }} supervisorctl_path: "{{ supervisor_ctl }}"
config={{ supervisor_cfg }} config: "{{ supervisor_cfg }}"
state=started state: started
when: celery_worker is defined and not disable_edx_services when: celery_worker is defined and not disable_edx_services
sudo_user: "{{ supervisor_service_user }}" sudo_user: "{{ supervisor_service_user }}"
tags: tags:
- manage - manage
- name: create symlinks from the venv bin dir - name: create symlinks from the venv bin dir and repo dir
file: > file:
src="{{ edxapp_venv_bin }}/{{ item }}" src: "{{ item }}"
dest={{ COMMON_BIN_DIR }}/{{ item.split('.')[0] }}.edxapp dest: "{{ COMMON_BIN_DIR }}/{{ (item | basename).split('.', 1) | first }}.edxapp"
state=link 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: with_items:
- manage.py - '{{ edxapp_venv_bin }}/python'
- '{{ edxapp_venv_bin }}/pip'
- '{{ edxapp_venv_bin }}/django-admin.py'
- '{{ edxapp_code_dir }}/manage.py'
tags: tags:
- install - install
- install:configuration - install:configuration
- name: remove read-only ssh key - name: remove read-only ssh key
file: path={{ edxapp_git_identity }} state=absent file:
path: "{{ edxapp_git_identity }}"
state: absent
when: EDXAPP_USE_GIT_IDENTITY when: EDXAPP_USE_GIT_IDENTITY
tags: tags:
- install - install
...@@ -422,25 +403,26 @@ ...@@ -422,25 +403,26 @@
- remove - remove
- aws - aws
- set_fact: edxapp_installed=true - set_fact:
edxapp_installed: true
- name: restart edxapp - name: restart edxapp
supervisorctl: > supervisorctl:
state=restarted name: "edxapp:"
supervisorctl_path={{ supervisor_ctl }} supervisorctl_path: "{{ supervisor_ctl }}"
config={{ supervisor_cfg }} config: "{{ supervisor_cfg }}"
name="edxapp:" state: restarted
when: edxapp_installed is defined and celery_worker is not defined and not disable_edx_services when: edxapp_installed is defined and celery_worker is not defined and not disable_edx_services
sudo_user: "{{ supervisor_service_user }}" sudo_user: "{{ supervisor_service_user }}"
tags: tags:
- manage - manage
- name: restart edxapp_workers - name: restart edxapp_workers
supervisorctl: > supervisorctl:
name="edxapp_worker:" name: "edxapp_worker:"
supervisorctl_path={{ supervisor_ctl }} supervisorctl_path: "{{ supervisor_ctl }}"
config={{ supervisor_cfg }} config: "{{ supervisor_cfg }}"
state=restarted state: restarted
when: edxapp_installed is defined and celery_worker is defined and not disable_edx_services when: edxapp_installed is defined and celery_worker is defined and not disable_edx_services
sudo_user: "{{ common_web_user }}" sudo_user: "{{ common_web_user }}"
tags: tags:
......
#!/bin/sh #!/bin/sh
{% if EDXAPP_USE_GIT_IDENTITY %}
exec /usr/bin/ssh -o StrictHostKeyChecking=no -i {{ edxapp_git_identity }} "$@" exec /usr/bin/ssh -o StrictHostKeyChecking=no -i {{ edxapp_git_identity }} "$@"
{% else %}
exec /usr/bin/ssh -o StrictHostKeyChecking=no "$@"
{% endif %}
\ No newline at end of file
#!/bin/sh
exec /usr/bin/ssh -o StrictHostKeyChecking=no "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment