diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8b42eb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.retry diff --git a/README.md b/README.md index d0c40a5..571454b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/example_multitenant_update_theme.sh b/example_multitenant_update_theme.sh new file mode 100755 index 0000000..1c0fbc5 --- /dev/null +++ b/example_multitenant_update_theme.sh @@ -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 threme 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 + diff --git a/main.yml b/main.yml index a5f78d4..03fb017 100644 --- a/main.yml +++ b/main.yml @@ -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" @@ -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) + diff --git a/roles/prepare-venv/tasks/main.yml b/roles/prepare-venv/tasks/main.yml index 25d638a..069e1fc 100644 --- a/roles/prepare-venv/tasks/main.yml +++ b/roles/prepare-venv/tasks/main.yml @@ -10,6 +10,7 @@ become_method: sudo become: yes become_user: root + when: MULTITENANT_SERVER_VARS is undefined - name: install libraries with pip pip: diff --git a/roles/update-com-theme/tasks/main.yml b/roles/update-com-theme/tasks/main.yml index a1f2b8d..37d2b15 100644 --- a/roles/update-com-theme/tasks/main.yml +++ b/roles/update-com-theme/tasks/main.yml @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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 }' @@ -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) diff --git a/update_theme.sh b/update_theme.sh index 034f81c..7c1dcdc 100755 --- a/update_theme.sh +++ b/update_theme.sh @@ -1,6 +1,8 @@ #!/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' @@ -8,7 +10,7 @@ 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 "" @@ -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" ]; @@ -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