Skip to content

Commit

Permalink
add multitenant provision support
Browse files Browse the repository at this point in the history
  • Loading branch information
dgamanenko committed Dec 7, 2016
1 parent 191f567 commit 119cffa
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.retry
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ cd themex_script
```
./update_theme.sh -brhi marvel-yellow-theme-eucalyptus https://github.com/raccoongang/themes_for_themex.io.git edx
inventory.ini file contained (in this case)
inventory.ini file contains (in this case)
[edx]
200.83.1.109
```
###setup theme branch in custom repo into some group of edx hosts (multitenant installation with local server-vars file):
```
./example_multitenant_update_theme.sh
*configure variables and prepare update and update_assets scripts before run
** script use update_theme.sh with -brhim mode:
./update_theme.sh -brhim theme_branch theme_repo edx_host_group hosts_file_path server_vars_file_path
and then run update/update_assets multitenant scripts
```

#### If you use some configuration server for setup theme on remote Edx instance you need to install ansible locally

Expand Down
37 changes: 37 additions & 0 deletions example_multitenant_update_theme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
THEME_BRANCH='marvel-yellow-theme-eucalyptus'
THEME_REPO='https://github.com/raccoongang/themes_for_themex.io.git'

CONFIGURATION_PLAYBOOKS_DIR='/encrypted/ansible/edx/playbooks'
THEMEX_SCRIPT_DIR='/encrypted/ansible/edx/playbooks/themex_script'
NEW_THEME_OR_JUST_UPDATE='--no-edx-update-run'

if [ "$1" == "--help" ];
then
echo ""
echo "script parameters:"
echo "'--help' : show current info"
echo "'--update-run' : install new theme"
echo "'--no-edx-update-run' : default script behaviour! -> just update theme repo and run update_assets"
echo ""
else
$THEMEX_SCRIPT_DIR/update_theme.sh -brhim $THEME_BRANCH $THEME_REPO all_host_edx $CONFIGURATION_PLAYBOOKS_DIR/hosts $CONFIGURATION_PLAYBOOKS_DIR/server-vars.yml
fi

if test "$#" -eq 1;
then
NEW_THEME_OR_JUST_UPDATE=$1
if [ "$NEW_THEME_OR_JUST_UPDATE" == "--no-edx-update-run" ];
then
##### RUN OpenEdx update_assets scripts ##########
$CONFIGURATION_PLAYBOOKS_DIR/update_assets_edx1.sh
$CONFIGURATION_PLAYBOOKS_DIR/update_assets_edx2.sh
elif [ "$NEW_THEME_OR_JUST_UPDATE" == "--edx-update-run" ];
then
##### RUN OpenEdx update scripts #################
cd $CONFIGURATION_PLAYBOOKS_DIR/
$CONFIGURATION_PLAYBOOKS_DIR/update_edx1.sh
$CONFIGURATION_PLAYBOOKS_DIR/update_edx2.sh
fi
fi

13 changes: 12 additions & 1 deletion main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
script_mode: "{{ mode }}"
when: mode is defined

- name: set_fact script_mode
set_fact:
MULTITENANT_SERVER_VARS_LOCAL_LOCATION: "{{ MULTITENANT_SERVER_VARS }}"
when: MULTITENANT_SERVER_VARS is defined

- name: set_fact script_mode
set_fact:
server_vars_path: "{{ MULTITENANT_SERVER_VARS }}"
when: MULTITENANT_SERVER_VARS is defined

- name: Check if devstack
fail:
msg: "Playbook not applicable for devstack"
Expand Down Expand Up @@ -51,10 +61,11 @@
- role: branch
theme_branch: "{{ theme_branch }}"
theme_repo: "{{ theme_repo }}"
when: (("{{ script_mode }}" == 'br') or ("{{ script_mode }}" == 'brh') or ("{{ script_mode }}" == 'brhi')) and (script_mode is defined) and (theme_branch is defined) and (theme_repo is defined)
when: (("{{ script_mode }}" == 'br') or ("{{ script_mode }}" == 'brh') or ("{{ script_mode }}" == 'brhi') or ("{{ script_mode }}" == 'brhim')) and (script_mode is defined) and (theme_branch is defined) and (theme_repo is defined)

- role: update-com-theme
theme_dir: "{{ theme_folder_main }}"
ignore_errors: no
SITE_THEME: "{{ theme_folder }}"
when: (theme_folder_main is defined) and (theme_folder is defined)

1 change: 1 addition & 0 deletions roles/prepare-venv/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
become_method: sudo
become: yes
become_user: root
when: MULTITENANT_SERVER_VARS is undefined

- name: install libraries with pip
pip:
Expand Down
59 changes: 53 additions & 6 deletions roles/update-com-theme/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
stat:
path: "{{ server_vars_path }}"
register: server_vars
when: MULTITENANT_SERVER_VARS_LOCAL_LOCATION is undefined

- name: set_fact multitenant_check
set_fact:
multitenant_check: True
when: (MULTITENANT_SERVER_VARS_LOCAL_LOCATION is undefined) and check_theme_root_exist.stat.exists and server_vars.stat.exists

- name: Check if "{{server_vars_path}}" exist for MULTITENANT_SERVER_VARS_LOCAL_LOCATION
local_action: stat path="{{ server_vars_path }}"
register: server_vars
when: MULTITENANT_SERVER_VARS_LOCAL_LOCATION is defined

- name: Check edx-platform vars file
fail:
Expand All @@ -39,7 +50,11 @@
become_method: sudo
become: yes
become_user: root
when: check_theme_root_exist.stat.exists and server_vars.stat.exists
when: (multitenant_check is defined) and (multitenant_check)

- name: Backup server-vars.yml for MULTITENANT_SERVER_VARS_LOCAL_LOCATION
local_action: command cp "{{ server_vars_path }}" "{{ server_vars_path }}_{{ current_back.stdout }}"
when: (MULTITENANT_SERVER_VARS_LOCAL_LOCATION is defined) and check_theme_root_exist.stat.exists and server_vars.stat.exists

- name: Ensure that server-vars contain EDXAPP_COMPREHENSIVE_THEME_DIR
lineinfile:
Expand All @@ -52,7 +67,15 @@
become_method: sudo
become: yes
become_user: root
when: check_theme_root_exist.stat.exists and server_vars.stat.exists
when: (multitenant_check is defined) and (multitenant_check)

- name: Ensure that server-vars contain EDXAPP_COMPREHENSIVE_THEME_DIR for MULTITENANT_SERVER_VARS_LOCAL_LOCATION
local_action: lineinfile dest="{{ server_vars_path }}"
regexp='^EDXAPP_COMPREHENSIVE_THEME_DIR:'
insertafter=EOF
line='EDXAPP_COMPREHENSIVE_THEME_DIR{{':'}} "{{ theme_dir }}/{{ theme_folder }}"'
state=present
when: (MULTITENANT_SERVER_VARS_LOCAL_LOCATION is defined) and check_theme_root_exist.stat.exists and server_vars.stat.exists

- name: Ensure that server-vars contain EDXAPP_COMPREHENSIVE_THEME_DIRS
lineinfile:
Expand All @@ -65,7 +88,15 @@
become_method: sudo
become: yes
become_user: root
when: check_theme_root_exist.stat.exists and server_vars.stat.exists
when: (multitenant_check is defined) and (multitenant_check)

- name: Ensure that server-vars contain EDXAPP_COMPREHENSIVE_THEME_DIRS for MULTITENANT_SERVER_VARS_LOCAL_LOCATION
local_action: lineinfile dest="{{ server_vars_path }}"
regexp='^EDXAPP_COMPREHENSIVE_THEME_DIRS:'
insertafter=EOF
line="EDXAPP_COMPREHENSIVE_THEME_DIRS{{':'}} [{{theme_dir}}]"
state=present
when: (MULTITENANT_SERVER_VARS_LOCAL_LOCATION is defined) and check_theme_root_exist.stat.exists and server_vars.stat.exists

- name: Ensure that server-vars contain EDXAPP_DEFAULT_SITE_THEME
lineinfile:
Expand All @@ -78,7 +109,15 @@
become_method: sudo
become: yes
become_user: root
when: check_theme_root_exist.stat.exists and server_vars.stat.exists
when: (multitenant_check is defined) and (multitenant_check)

- name: Ensure that server-vars contain EDXAPP_DEFAULT_SITE_THEME for MULTITENANT_SERVER_VARS_LOCAL_LOCATION
local_action: lineinfile dest="{{ server_vars_path }}"
regexp='^EDXAPP_DEFAULT_SITE_THEME:'
insertafter=EOF
line='EDXAPP_DEFAULT_SITE_THEME{{":"}} "{{ SITE_THEME }}"'
state=present
when: (MULTITENANT_SERVER_VARS_LOCAL_LOCATION is defined) and check_theme_root_exist.stat.exists and server_vars.stat.exists

- name: Ensure that server-vars contain EDXAPP_ENABLE_COMPREHENSIVE_THEMING
lineinfile:
Expand All @@ -91,7 +130,15 @@
become_method: sudo
become: yes
become_user: root
when: check_theme_root_exist.stat.exists and server_vars.stat.exists
when: (multitenant_check is defined) and (multitenant_check)

- name: Ensure that server-vars contain EDXAPP_ENABLE_COMPREHENSIVE_THEMING for MULTITENANT_SERVER_VARS_LOCAL_LOCATION
local_action: lineinfile dest="{{server_vars_path}}"
regexp='^EDXAPP_ENABLE_COMPREHENSIVE_THEMING:'
insertafter=EOF
line='EDXAPP_ENABLE_COMPREHENSIVE_THEMING{{":"}} true'
state=present
when: (MULTITENANT_SERVER_VARS_LOCAL_LOCATION is defined) and check_theme_root_exist.stat.exists and server_vars.stat.exists

- name: Get current edx-platform git branch
shell: cd /edx/app/edxapp/edx-platform/ && git branch | grep \* | sed "s/(\|)//g" | sed "s/*//g" | awk '{print $NF }'
Expand All @@ -105,5 +152,5 @@
become_method: sudo
become: yes
become_user: root
when: check_theme_root_exist.stat.exists and server_vars.stat.exists
when: (multitenant_check is defined) and (multitenant_check)

31 changes: 22 additions & 9 deletions update_theme.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/bin/bash

ASNIBLE_BIN_DIR='/encrypted/ansible/edx/edxvenv/bin'
INI_FILE='inventory.ini'
MULTITENANT_SERVER_VARS=$6

mode_local_zip='-l'
mode_remote_zip='-r'
mode_branch_rg='-b'
mode_branch_custom_repo='-br'
mode_branch_custom_repo_remote_edx_host='-brh'
mode_branch_custom_repo_remote_group_edx_host='-brhi'

mode_multitenant='-brhim'
if test "$#" -le 1;
then
echo ""
Expand All @@ -26,10 +28,15 @@ then
echo ""
echo "setup theme branch in custom repo into some group of edx hosts: ./update_theme.sh $mode_branch_custom_repo_remote_group_edx_host theme_branch theme_repo edx_host_group (!you need to modify inventory.ini file!)"
echo ""
echo "setup theme branch in custom repo into some group of edx hosts (multitenant installation with local server-vars file): ./update_theme.sh $mode_multitenant theme_branch theme_repo edx_host_group hosts_file_path server_vars_file_path"
echo ""
else

ansible-playbook -c local -i "localhost," prepare.yml

if test "$#" -eq 6;
then
$ASNIBLE_BIN_DIR/ansible-playbook -c local -i "localhost," prepare.yml -e "MULTITENANT_SERVER_VARS=$6"
else
$ASNIBLE_BIN_DIR/ansible-playbook -c local -i "localhost," prepare.yml
fi
if test "$#" -eq 2;
then
if [ "$1" == "$mode_local_zip" ];
Expand All @@ -54,11 +61,17 @@ else
if [ "$1" == "$mode_branch_custom_repo_remote_edx_host" ];
then
~/.edxthemevenv/bin/ansible-playbook -i ",$4" main.yml -e "edx_hosts=$4" -e "mode=${1//[-]/}" -e "theme_branch=$2 theme_repo=$3"
elif [ "$1" == "$mode_branch_custom_repo_remote_group_edx_host" ];
elif [ "$1" == "$mode_branch_custom_repo_remote_group_edx_host" ];
then
~/.edxthemevenv/bin/ansible-playbook -i $INI_FILE main.yml --limit $4 -e "edx_hosts=$4" -e "mode=${1//[-]/}" -e "theme_branch=$2 theme_repo=$3"
fi
elif test "$#" -eq 6;
then
~/.edxthemevenv/bin/ansible-playbook -i $INI_FILE main.yml --limit $4 -e "edx_hosts=$4" -e "mode=${1//[-]/}" -e "theme_branch=$2 theme_repo=$3"
fi
fi

echo "run script in multitenant mode..."
if [ "$1" == "$mode_multitenant" ];
then
~/.edxthemevenv/bin/ansible-playbook -i $5 main.yml --limit $4 -e "edx_hosts=$4" -e "mode=${1//[-]/}" -e "theme_branch=$2 theme_repo=$3" -e "MULTITENANT_SERVER_VARS=$6"
fi
fi
fi

0 comments on commit 119cffa

Please sign in to comment.