Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multitenant support to script #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.retry
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
##OpenEdx Comprehensive theme autoinstall
####*Playbook not applicable for Vagrant devstack

###QUICK START:
###REQUIREMENTS:
Expand Down Expand Up @@ -55,11 +56,24 @@ 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 --edx-update-run

# or you can just update theme repo and run update_assets:

./example_multitenant_update_theme.sh --no-edx-update-run

*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'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not always /encrypted. It can be variable and use default value if not set.

Copy link
Contributor Author

@dgamanenko dgamanenko Dec 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sidorovdmitry
it's just an example script (example_multitenant_update_theme.sh)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@dgamanenko dgamanenko Dec 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sidorovdmitry
it's just an example script (example_multitenant_update_theme.sh)


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

15 changes: 13 additions & 2 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need 2 equal variables?

Copy link
Contributor Author

@dgamanenko dgamanenko Dec 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sidorovdmitry
because of playbook multifunctionality. We cannot use server_vars_path variable here

when: MULTITENANT_SERVER_VARS is undefined

- name: Check if devstack
fail:
msg: "Playbook not applicable for devstack"
when: ((devstack.stat.exists) and (("{{ script_mode }}" == 'l') or ("{{ script_mode }}" == 'r') or ("{{ script_mode }}" == 'b') or ("{{ script_mode }}" == 'br')))
when: devstack.stat.exists

- name: Generate SSH keys for user ubuntu
user:
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theme_branch: "{{ theme_branch|default('master') }}"
theme_repo: "{{ theme_repo|default( some our theme repo ) }}"```
when: script_mode is defined and script_mode  in 'brhim' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sidorovdmitry updated with defaults

when: script_mode is defined and script_mode  in 'brhim' ? - not applicable (f.e. 'him' in 'brhim' is True but not supported mode)


- 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:'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One tab for yaml = 2 spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sidorovdmitry fixed

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