-
Notifications
You must be signed in to change notification settings - Fork 1
/
rolling_execute.yml
48 lines (42 loc) · 2.02 KB
/
rolling_execute.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
# Playbook that executes a shell command using a rolling restart approach.
# This can be useful to apply a rolling docker restart or to download/pull a new docker image.
#
# Example:
# ansible-playbook -i nau-data/envs/<env>/hosts.ini rolling_execute.yml --limit <group> -e command='ls /tmp'
#
# Example that executes multiple commands:
# ansible-playbook -i nau-data/envs/<env>/hosts.ini rolling_execute.yml --limit openedx_docker_servers -e "command='docker pull overhangio/openedx-forum:14.0.0 && docker pull overhangio/openedx-notes:14.0.1 && docker pull overhangio/openedx-discovery:14.0.2 && docker pull nauedu/openedx-analytics-data-api:nau-nutmeg.master-XXXXXX-build-yy && docker pull nauedu/openedx-insights:nau-nutmeg.master-XXXXX-build-yy && docker pull nauedu/openedx:nau-nutmeg.master-build-XXX-YYYYYYY'"
#
# Example that restarts the Open edX LMS and Studio:
# ansible-playbook -i nau-data/envs/<env>/hosts.ini rolling_execute.yml --limit openedx_docker_servers -e "command='make -C /nau/ops/openedx restart-lms restart-cms'"
---
- hosts: all
serial: "{{ serial_number | default(1) }}"
become: True
gather_facts: True
vars:
rolling_deploy_enabled: true
tasks:
- name: Check if 'command' is defined
assert:
that: command is defined
fail_msg: You need to add a 'command' parameter
quiet: true
- import_tasks: tasks/close_node.yml
- name: Print stdout of command output
debug:
msg: "Executing command: {{ command }}"
# Real execute the command
- name: Real execute command
shell: "{{ command }}"
register: exec_output
- name: Print stdout of command output
debug:
msg: "{{ exec_output.stdout_lines }}"
when: exec_output is defined and exec_output.stdout_lines is defined
- name: Print stderr of command output
debug:
msg: "{{ exec_output.stderr_lines }}"
when: exec_output is defined and exec_output.stderr_lines is defined
- import_tasks: tasks/healthcheck.yml
- import_tasks: tasks/open_node.yml