-
Notifications
You must be signed in to change notification settings - Fork 1
/
openedx_commands_multiple_per_day.yml
95 lines (92 loc) · 4.76 KB
/
openedx_commands_multiple_per_day.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Run multiple tasks on openedx stack.
#
# It finds the docker swarm node where it is run each container (discovery or lms) and executes
# the django manage command inside the container.
#
# Discovery:
# - Refresh course metadata
# - Remove unused indexes
# - Update index
#
# LMS:
# - cache programs data.
# - pull SAML configuration.
#
# Examples:
# To run all run the playbook with:
# ansible-playbook -i nau-data/envs/<env>/hosts.ini openedx_commands_8timesday_compose.yml -e run_all=true
#
# To run specific step use:
# ansible-playbook -i nau-data/envs/<env>/hosts.ini openedx_commands_8timesday_compose.yml -e discovery_refresh_course_metadata=true
# ansible-playbook -i nau-data/envs/<env>/hosts.ini openedx_commands_8timesday_compose.yml -e discovery_remove_unused_indexes=true
# ansible-playbook -i nau-data/envs/<env>/hosts.ini openedx_commands_8timesday_compose.yml -e discovery_update_index=true
# ansible-playbook -i nau-data/envs/<env>/hosts.ini openedx_commands_8timesday_compose.yml -e lms_cache_programs=true
# ansible-playbook -i nau-data/envs/<env>/hosts.ini openedx_commands_8timesday_compose.yml -e lms_saml_pull=true
#
---
- name: Run openedx django commands on different containers
hosts: "{{ (groups['openedx_docker_servers'] | shuffle)[0] }}"
become: True
gather_facts: True
order: shuffle # run on a random server
vars:
_discovery_refresh_course_metadata: "{{ run_all | default(discovery_refresh_course_metadata) | default(false) | bool }}"
_discovery_remove_unused_indexes: "{{ run_all | default(discovery_remove_unused_indexes) | default(false) | bool }}"
_discovery_update_index: "{{ run_all | default(discovery_update_index) | default(false) | bool }}"
_lms_cache_programs: "{{ run_all | default(lms_cache_programs) | default(false) | bool }}"
_lms_saml_pull: "{{ run_all | default(lms_saml_pull) | default(false) | bool }}"
# Configuration of discovery and lms django commands with docker service and its shell command to execute.
commands_to_execute:
# discovery tasks
- docker_exec_name: discovery refresh course metadata
docker_container_name: openedx_discovery
docker_exec_command: python manage.py refresh_course_metadata --no-color
docker_exec_output_fact: discovery_refresh_course_metadata_output
when: "{{ _discovery_refresh_course_metadata }}"
- docker_exec_name: discovery remove unused indexes
docker_container_name: openedx_discovery
docker_exec_command: python manage.py remove_unused_indexes --no-color
docker_exec_output_fact: discovery_remove_unused_indexes_output
when: "{{ _discovery_remove_unused_indexes }}"
- docker_exec_name: discovery update index
docker_container_name: openedx_discovery
docker_exec_command: python manage.py update_index --disable-change-limit --no-color
docker_exec_output_fact: discovery_update_index_output
when: "{{ _discovery_update_index }}"
# lms tasks
- docker_exec_name: lms cache programs
docker_container_name: openedx_lms
docker_exec_command: python manage.py lms cache_programs --settings nau_production
docker_exec_output_fact: lms_cache_programs_output
when: "{{ _lms_cache_programs }}"
- docker_exec_name: lms saml pull
docker_container_name: openedx_lms
docker_exec_command: python manage.py lms saml --pull --settings nau_production
docker_exec_output_fact: lms_saml_pull_output
when: "{{ _lms_saml_pull }}"
tasks:
- name: Execute each job inside a docker container
include_role:
name: docker_execute
vars:
docker_exec_name: "{{ exec.docker_exec_name }}"
docker_container_name: "{{ exec.docker_container_name }}"
docker_exec_command: "{{ exec.docker_exec_command }}"
docker_exec_ignore_errors: "{{ exec.docker_exec_ignore_errors | default(True) }}"
docker_exec_output_fact: "{{ exec.docker_exec_output_fact | default(None) }}"
when: exec.when | default(true)
loop_control:
loop_var: exec
label: "Execute {{ exec.docker_exec_name }}"
loop: "{{ commands_to_execute }}"
# needed only because we are ignoring the errors on previous task and now we are checking if
# each has finished with success.
- name: Check if above commands have finished with success
assert:
that: hostvars[inventory_hostname][check_cmd.docker_exec_output_fact].rc == 0 and "ERROR" not in hostvars[inventory_hostname][check_cmd.docker_exec_output_fact].stdout
quiet: true
when: ( check_cmd.when | default(true) ) and not ansible_check_mode
loop_control:
loop_var: check_cmd
label: Check if '{{ check_cmd.docker_exec_name }}' have finished with success
loop: "{{ commands_to_execute }}"