summaryrefslogtreecommitdiff
path: root/salt/openbook/ansible/files/stop_start_openbook.yaml
blob: 28c5d58e15ecb1b09856c70f72ea49ed38f333ad (plain)
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
---
- name: "Verify action to take"
  hosts: localhost
  tasks:
    - name: "Check that -e 'action=[stop|start|restart]' was passed in"
      fail:
        msg: "The variable 'action' was not passed in with a value of 'stop', 'start' or 'restart' on the command line."
      when: action not in ["stop", "start", "restart"]

- name: "Stop Openbook"
  hosts: "{{ groups['target']|sort(reverse=True) }}"
  serial: 1
  tasks:
    - name: "Stop Openbook"
      service:
        name: "{{ item.name }}"
        state: stopped
        runlevel: "{{ item.runlevel }}"
      with_items:
        - { name: openbook, runlevel: default }
        - { name: openbook-debug, runlevel: default }
      ignore_errors: True
      when: action == "stop"

    - name: "Delete Openbook containers"
      shell: |
        for cont in $(docker ps | grep -v 'COMMAND' | awk '{print $1}'); do
            docker stop ${cont}
        done
        docker container prune -f
      ignore_errors: True
      when: action in ["stop", "restart"] 

- name: "Start Openbook"
  hosts: "{{ groups['target']|sort }}"
  serial: 1
  tasks:
    - name: "Start Openbook"
      service:
        name: "{{ item.name }}"
        state: started
        runlevel: "{{ item.runlevel }}"
      with_items:
        - { name: openbook, runlevel: default }
      when: action in ["start", "restart"] and extra_args != "debug"

    - name: "Start Openbook in debug mode"
      service:
        name: "{{ item.name }}"
        state: started
        runlevel: "{{ item.runlevel }}"
      with_items:
        - { name: openbook-debug, runlevel: default }
      when: action in ["start", "restart"] and extra_args == "debug"