summaryrefslogtreecommitdiff
path: root/salt/openbook/ansible/files/openbook.yaml
blob: bb9c6edb2052b248ba5c2b2c449609b87ced406b (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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
---
- name: "Install Openbook"
  hosts: target
  tasks:
    - name: "Install network tools"
      apt:
        pkg: "{% raw %}{{ item }}{% endraw %}"
        state: present
      with_items:
        - netcat-openbsd
        - lsof
      when: ansible_distribution == "Ubuntu"

    - name: "Install network tools"
      yum:
        name: "{% raw %}{{ item }}{% endraw %}"
        state: present
      with_items:
        - nmap-ncat
        - lsof
      when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS"

    - name: "Install network tools"
      portage:
        package: "{% raw %}{{ item }}{% endraw %}"
        update: yes
        changed_use: yes
      with_items:
        - net-analyzer/netcat
        - sys-process/lsof
      when: ansible_distribution == "Gentoo"

    - name: "Write hosts entry"
      lineinfile:
        dest: /etc/hosts
        regexp: "{% raw %}{{ item.regexp }}{% endraw %}"
        line: "{% raw %}{{ item.line }}{% endraw %}"
      with_items:
        - { regexp: '^127\.0\.0\.1.*$', line: "127.0.0.1 localhost {% raw %}{{ inventory_hostname }} {{ ansible_nodename }}{% endraw %}" }

    - name: "Create Openbook directories"
      file:
        path: "{% raw %}{{ item.path }}{% endraw %}"
        state: directory
        mode: "{% raw %}{{ item.mode }}{% endraw %}"
      with_items:
        - { path: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/database, mode: "0755" }
        - { path: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/job_scheduler_server, mode: "0755" }
        - { path: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/workflow_server, mode: "0755" }
        - { path: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/admin_api_server, mode: "0755" }
        - { path: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/customer_api_server, mode: "0755" }
        - { path: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/admin_web_ui, mode: "0755" }
        - { path: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/customer_web_ui, mode: "0755" }
        - { path: {{ pillar["database"]["dirs"]["etc_openbook_database_conf.d"]["name"] }}, mode: "0755" }
        - { path: {{ pillar["database"]["dirs"]["etc_openbook_database_bin"]["name"] }}, mode: "0755" }
        - { path: {{ pillar["database"]["dirs"]["var_lib_mysql"]["name"] }}, mode: "0777" }
        - { path: {{ pillar["database"]["dirs"]["var_log_mysql"]["name"] }}, mode: "0777" }
        - { path: {{ pillar["job_scheduler_server"]["dirs"]["etc_openbook_job_scheduler_server"]["name"] }}, mode: "0777" }
        - { path: {{ pillar["workflow_server"]["dirs"]["etc_openbook_workflow_server"]["name"] }}, mode: "0777" }
        - { path: {{ pillar["admin_api_server"]["dirs"]["etc_openbook_admin_api_server"]["name"] }}, mode: "0777" }
        - { path: {{ pillar["customer_api_server"]["dirs"]["etc_openbook_customer_api_server"]["name"] }}, mode: "0777" }
        - { path: {{ pillar["admin_web_ui"]["dirs"]["etc_openbook_admin_web_ui"]["name"] }}, mode: "0777" }
        - { path: {{ pillar["customer_web_ui"]["dirs"]["etc_openbook_customer_web_ui"]["name"] }}, mode: "0777" }
        - { path: {{ pillar["job_scheduler_server"]["log"] }}, mode: "0777" }
        - { path: {{ pillar["workflow_server"]["log"] }}, mode: "0777" }
        - { path: {{ pillar["admin_api_server"]["log"] }}, mode: "0777" }
        - { path: {{ pillar["customer_api_server"]["log"] }}, mode: "0777" }
        - { path: {{ pillar["admin_web_ui"]["log"] }}, mode: "0777" }
        - { path: {{ pillar["customer_web_ui"]["log"] }}, mode: "0777" }

    - name: "Create Openbook files"
      template:
        src: "../templates/{% raw %}{{ item.src }}{% endraw %}"
        dest: "{% raw %}{{ item.dest }}{% endraw %}"
        mode: "{% raw %}{{ item.mode }}{% endraw %}"
        owner: root
        group: root
      with_items:
        - { src: ci/{{ pillar["ci"]["files"]["openbookctl"]["path"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }}, mode: "0755" }
        - { src: database/{{ pillar["database"]["files"]["run_sh"]["path"] }}/{{ pillar["database"]["files"]["run_sh"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/database/{{ pillar["database"]["files"]["run_sh"]["name"] }}, mode: "0755" }
        - { src: job_scheduler_server/{{ pillar["job_scheduler_server"]["files"]["run_sh"]["path"] }}/{{ pillar["job_scheduler_server"]["files"]["run_sh"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/job_scheduler_server/{{ pillar["job_scheduler_server"]["files"]["run_sh"]["name"] }}, mode: "0755" }
        - { src: workflow_server/{{ pillar["workflow_server"]["files"]["run_sh"]["path"] }}/{{ pillar["workflow_server"]["files"]["run_sh"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/workflow_server/{{ pillar["workflow_server"]["files"]["run_sh"]["name"] }}, mode: "0755" }
        - { src: admin_api_server/{{ pillar["admin_api_server"]["files"]["run_sh"]["path"] }}/{{ pillar["admin_api_server"]["files"]["run_sh"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/admin_api_server/{{ pillar["admin_api_server"]["files"]["run_sh"]["name"] }}, mode: "0755" }
        - { src: customer_api_server/{{ pillar["customer_api_server"]["files"]["run_sh"]["path"] }}/{{ pillar["customer_api_server"]["files"]["run_sh"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/customer_api_server/{{ pillar["customer_api_server"]["files"]["run_sh"]["name"] }}, mode: "0755" }
        - { src: admin_web_ui/{{ pillar["admin_web_ui"]["files"]["run_sh"]["path"] }}/{{ pillar["admin_web_ui"]["files"]["run_sh"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/admin_web_ui/{{ pillar["admin_web_ui"]["files"]["run_sh"]["name"] }}, mode: "0755" }
        - { src: customer_web_ui/{{ pillar["customer_web_ui"]["files"]["run_sh"]["path"] }}/{{ pillar["customer_web_ui"]["files"]["run_sh"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/customer_web_ui/{{ pillar["customer_web_ui"]["files"]["run_sh"]["name"] }}, mode: "0755" }
        - { src: job_scheduler_server/{{ pillar["job_scheduler_server"]["files"]["job_scheduler_server_json"]["path"] }}/{{ pillar["job_scheduler_server"]["files"]["job_scheduler_server_json"]["name"] }}, dest: {{ pillar["job_scheduler_server"]["files"]["job_scheduler_server_json"]["path"] }}/{{ pillar["job_scheduler_server"]["files"]["job_scheduler_server_json"]["name"] }}, mode: "0644" }
        - { src: workflow_server/{{ pillar["workflow_server"]["files"]["workflow_server_json"]["path"] }}/{{ pillar["workflow_server"]["files"]["workflow_server_json"]["name"] }}, dest: {{ pillar["workflow_server"]["files"]["workflow_server_json"]["path"] }}/{{ pillar["workflow_server"]["files"]["workflow_server_json"]["name"] }}, mode: "0644" }
        - { src: admin_api_server/{{ pillar["admin_api_server"]["files"]["admin_api_server_json"]["path"] }}/{{ pillar["admin_api_server"]["files"]["admin_api_server_json"]["name"] }}, dest: {{ pillar["admin_api_server"]["files"]["admin_api_server_json"]["path"] }}/{{ pillar["admin_api_server"]["files"]["admin_api_server_json"]["name"] }}, mode: "0644" }
        - { src: customer_api_server/{{ pillar["customer_api_server"]["files"]["customer_api_server_json"]["path"] }}/{{ pillar["customer_api_server"]["files"]["customer_api_server_json"]["name"] }}, dest: {{ pillar["customer_api_server"]["files"]["customer_api_server_json"]["path"] }}/{{ pillar["customer_api_server"]["files"]["customer_api_server_json"]["name"] }}, mode: "0644" }
        - { src: admin_web_ui/{{ pillar["admin_web_ui"]["files"]["admin_web_ui_json"]["path"] }}/{{ pillar["admin_web_ui"]["files"]["admin_web_ui_json"]["name"] }}, dest: {{ pillar["admin_web_ui"]["files"]["admin_web_ui_json"]["path"] }}/{{ pillar["admin_web_ui"]["files"]["admin_web_ui_json"]["name"] }}, mode: "0644" }
        - { src: customer_web_ui/{{ pillar["customer_web_ui"]["files"]["customer_web_ui_json"]["path"] }}/{{ pillar["customer_web_ui"]["files"]["customer_web_ui_json"]["name"] }}, dest: {{ pillar["customer_web_ui"]["files"]["customer_web_ui_json"]["path"] }}/{{ pillar["customer_web_ui"]["files"]["customer_web_ui_json"]["name"] }}, mode: "0644" }
        - { src: database/{{ pillar["database"]["files"]["root_my_cnf"]["path"] }}/{{ pillar["database"]["files"]["root_my_cnf"]["name"] }}, dest: {{ pillar["database"]["files"]["root_my_cnf"]["path"] }}/{{ pillar["database"]["files"]["root_my_cnf"]["name"] }}, mode: "0644" }
        - { src: database/{{ pillar["database"]["files"]["create_openbook_schemas"]["path"] }}/{{ pillar["database"]["files"]["create_openbook_schemas"]["name"] }}, dest: {{ pillar["database"]["files"]["create_openbook_schemas"]["path"] }}/{{ pillar["database"]["files"]["create_openbook_schemas"]["name"] }}, mode: "0755" }
        - { src: database/{{ pillar["database"]["files"]["debian_cnf"]["path"] }}/{{ pillar["database"]["files"]["debian_cnf"]["name"] }}, dest: {{ pillar["database"]["files"]["debian_cnf"]["path"] }}/{{ pillar["database"]["files"]["debian_cnf"]["name"] }}, mode: "0644" }
        - { src: database/{{ pillar["database"]["files"]["cluster_cnf"]["path"] }}/{{ pillar["database"]["files"]["cluster_cnf"]["name"] }}, dest: {{ pillar["database"]["files"]["cluster_cnf"]["path"] }}/{{ pillar["database"]["files"]["cluster_cnf"]["name"] }}, mode: "0644" }
        - { src: database/{{ pillar["database"]["files"]["debconfrc"]["path"] }}/{{ pillar["database"]["files"]["debconfrc"]["name"] }}, dest: {{ pillar["database"]["files"]["debconfrc"]["path"] }}/{{ pillar["database"]["files"]["debconfrc"]["name"] }}, mode: "0644" }
        - { src: database/{{ pillar["database"]["files"]["fix_permissions_sh"]["path"] }}/{{ pillar["database"]["files"]["fix_permissions_sh"]["name"] }}, dest: {{ pillar["database"]["files"]["fix_permissions_sh"]["path"] }}/{{ pillar["database"]["files"]["fix_permissions_sh"]["name"] }}, mode: "0755" }
        - { src: database/{{ pillar["database"]["files"]["start_galera_node_sh"]["path"] }}/{{ pillar["database"]["files"]["start_galera_node_sh"]["name"] }}, dest: {{ pillar["database"]["files"]["start_galera_node_sh"]["path"] }}/{{ pillar["database"]["files"]["start_galera_node_sh"]["name"] }}, mode: "0755" }

    - name: "Create Openbook files"
      copy:
        src: "../files/{% raw %}{{ item.src }}{% endraw %}"
        dest: "{% raw %}{{ item.dest }}{% endraw %}"
        mode: "{% raw %}{{ item.mode }}{% endraw %}"
        owner: root
        group: root
      with_items:
        - { src: ci/{{ pillar["ci"]["files"]["cloudcfg_sh"]["path"] }}/{{ pillar["ci"]["files"]["cloudcfg_sh"]["name"] }}, dest: {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["cloudcfg_sh"]["name"] }}, mode: "0755" }
        - { src: database/{{ pillar["database"]["files"]["my_cnf"]["path"] }}/{{ pillar["database"]["files"]["my_cnf"]["name"] }}, dest: {{ pillar["database"]["files"]["my_cnf"]["path"] }}/{{ pillar["database"]["files"]["my_cnf"]["name"] }}, mode: "0644" }

    - name: "Create Openbook init script: Ubuntu"
      template:
        src: "../templates/{% raw %}{{ item.src }}{% endraw %}"
        dest: "{% raw %}{{ item.dest }}{% endraw %}"
        mode: "{% raw %}{{ item.mode }}{% endraw %}"
        owner: root
        group: root
      with_items:
        - { src: ci/{{ pillar["ci"]["files"]["openbook_ubuntu_start"]["path"] }}/{{ pillar["ci"]["files"]["openbook_ubuntu_start"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" }
        - { src: ci/{{ pillar["ci"]["files"]["openbook_ubuntu_debug"]["path"] }}/{{ pillar["ci"]["files"]["openbook_ubuntu_debug"]["name"] }}, dest: /etc/init.d/openbook-debug, mode: "0755" }
      when: ansible_distribution == "Ubuntu"

    - name: "Create Openbook init script: Redhat"
      template:
        src: "../templates/{% raw %}{{ item.src }}{% endraw %}"
        dest: "{% raw %}{{ item.dest }}{% endraw %}"
        mode: "{% raw %}{{ item.mode }}{% endraw %}"
        owner: root
        group: root
      with_items:
        - { src: ci/{{ pillar["ci"]["files"]["openbook_redhat_start"]["path"] }}/{{ pillar["ci"]["files"]["openbook_redhat_start"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" }
        - { src: ci/{{ pillar["ci"]["files"]["openbook_redhat_debug"]["path"] }}/{{ pillar["ci"]["files"]["openbook_redhat_debug"]["name"] }}, dest: /etc/init.d/openbook-debug, mode: "0755" }
      when: ansible_distribution == "RedHat" or ansible_distribution == "CentOS"

    - name: "Create Openbook init script: Gentoo"
      template:
        src: "../templates/{% raw %}{{ item.src }}{% endraw %}"
        dest: "{% raw %}{{ item.dest }}{% endraw %}"
        mode: "{% raw %}{{ item.mode }}{% endraw %}"
        owner: root
        group: root
      with_items:
        - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo_openrc_start"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo_openrc_start"]["name"] }}, dest: /etc/init.d/openbook, mode: "0755" }
        - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo_openrc_debug"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo_openrc_debug"]["name"] }}, dest: /etc/init.d/openbook-debug, mode: "0755" }
      when: ansible_distribution == "Gentoo" and ansible_service_mgr == "openrc"

    - name: "Create Openbook systemd scripts: Gentoo"
      template:
        src: "../templates/{% raw %}{{ item.src }}{% endraw %}"
        dest: "{% raw %}{{ item.dest }}{% endraw %}"
        mode: "{% raw %}{{ item.mode }}{% endraw %}"
        owner: root
        group: root
      with_items:
        - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo_systemd_start"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo_systemd_start"]["name"] }}, dest: /etc/systemd/system/openbook.service, mode: "0644" }
        - { src: ci/{{ pillar["ci"]["files"]["openbook_gentoo_systemd_debug"]["path"] }}/{{ pillar["ci"]["files"]["openbook_gentoo_systemd_debug"]["name"] }}, dest: /etc/systemd/system/openbook-debug.service, mode: "0644" }
      when: ansible_distribution == "Gentoo" and ansible_service_mgr == "systemd"

    - name: "Add service script to systemd"
      shell: systemctl enable openbook.service
      when: ansible_distribution == "Ubuntu" or ansible_distribution == "RedHat" or ansible_distribution == "CentOS" or (ansible_distribution == "Gentoo" and ansible_service_mgr == "systemd")

    - name: "Enable openbook service"
      service:
        name: "{% raw %}{{ item.name }}{% endraw %}"
        enabled: yes
        runlevel: "{% raw %}{{ item.runlevel }}{% endraw %}"
      with_items:
        - { name: openbook, runlevel: default }
      when: openbook_install_database|string() == "False"

    - name: "Disable openbook service"
      service:
        name: "{% raw %}{{ item.name }}{% endraw %}"
        enabled: no
        runlevel: "{% raw %}{{ item.runlevel }}{% endraw %}"
      with_items:
        - { name: openbook, runlevel: default }
      when: openbook_install_database|string() == "True"

- name: "Stop Openbook"
  include: stop_start_openbook.yaml action=stop

- name: "Install Openbook"
  hosts: target
  tasks:
    - name: "Delete existing docker images"
      shell: |
        {{ pillar["ansible"]["dirs"]["output"]["name"] }}/{{ pillar["ci"]["files"]["openbookctl"]["name"] }} stop || true
        for i in $(docker images | grep -v CREATED | awk '{print $3}'); do
            docker rmi --force $i
        done
        docker container prune -f
      ignore_errors: True

    - name: "Pull docker images"
      shell: |
        docker login --username "{% raw %}{{ openbook_docker_registry_username }}{% endraw %}" --password "{% raw %}{{ openbook_docker_registry_password }}{% endraw %}" "{% raw %}{{ openbook_docker_registry_url }}{% endraw %}"
        if [ "{% raw %}{{ openbook_install_database|string() }}{% endraw %}" == "True" ]; then
            docker pull "{% raw %}{{ openbook_docker_registry_url }}{% endraw %}/{{ pillar["database"]["image_name"] }}"
        fi
        if [ "{% raw %}{{ openbook_install_job_scheduler_server|string() }}{% endraw %}" == "True" ]; then
            docker pull "{% raw %}{{ openbook_docker_registry_url }}{% endraw %}/{{ pillar["job_scheduler_server"]["image_name"] }}"
        fi
        if [ "{% raw %}{{ openbook_install_workflow_server|string() }}{% endraw %}" == "True" ]; then
            docker pull "{% raw %}{{ openbook_docker_registry_url }}{% endraw %}/{{ pillar["workflow_server"]["image_name"] }}"
        fi
        if [ "{% raw %}{{ openbook_install_admin_api_server|string() }}{% endraw %}" == "True" ]; then
            docker pull "{% raw %}{{ openbook_docker_registry_url }}{% endraw %}/{{ pillar["admin_api_server"]["image_name"] }}"
        fi
        if [ "{% raw %}{{ openbook_install_customer_api_server|string() }}{% endraw %}" == "True" ]; then
            docker pull "{% raw %}{{ openbook_docker_registry_url }}{% endraw %}/{{ pillar["customer_api_server"]["image_name"] }}"
        fi
        if [ "{% raw %}{{ openbook_install_admin_web_ui|string() }}{% endraw %}" == "True" ]; then
            docker pull "{% raw %}{{ openbook_docker_registry_url }}{% endraw %}/{{ pillar["admin_web_ui"]["image_name"] }}"
        fi
        if [ "{% raw %}{{ openbook_install_customer_web_ui|string() }}{% endraw %}" == "True" ]; then
            docker pull "{% raw %}{{ openbook_docker_registry_url }}{% endraw %}/{{ pillar["customer_web_ui"]["image_name"] }}"
        fi
      args:
        executable: /bin/bash

- name: "Start Openbook"
  include: stop_start_openbook.yaml action=start
  when: openbook_start_app == True