-
Notifications
You must be signed in to change notification settings - Fork 0
/
osw.yml
114 lines (101 loc) · 4.04 KB
/
osw.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# osw.yml
# Authors:
# Andreas Räder, https://github.com/raederan
# Simon Stier, https://github.com/simontaurus
# Begin: Check Ansible User
- name: Check Ansible User
hosts: "{{ target_hosts | default('all') }}"
vars:
name: osw # used as folder name
gather_facts: false
tasks:
- name: Fail reliably if 'ansible_user' is not defined
fail:
msg: "You need to set the ansible_user by using the flag -u <USERNAME> when running the playbook!"
when: ansible_user is not defined
- name: Print 'ansible_user'
debug:
msg: "ansible_user: {{ ansible_user }}"
when: ansible_user is defined
# End: Check Ansible User
# Begin: Deploy Open Semantic World (OSW)
- name: Deploy Open Semantic World (OSW)
hosts: "{{ target_hosts | default('all') }}"
tasks:
- name: Verify SSH connection
ansible.builtin.wait_for_connection:
- name: Clone Open Semantic World (OSW) repository
ansible.builtin.git:
repo: https://github.com/OpenSemanticLab/osl-mw-docker-compose.git
dest: /usr/local/docker-container/{{ instance_name }}
version: "{{ git_osw_version }}"
- name: Change ownership of osw/mediawiki/data directory
ansible.builtin.file:
path: /usr/local/docker-container/{{ instance_name }}/mediawiki/data
owner: "{{ ansible_user }}"
group: www-data
state: directory
mode: 0775
- name: Copy .env.example to .env
ansible.builtin.copy:
src: /usr/local/docker-container/{{ instance_name }}/.env.example
dest: /usr/local/docker-container/{{ instance_name }}/.env
remote_src: yes
owner: "{{ ansible_user }}"
mode: 0644
force: no
- name: Create/Replace values by key dict in .env file
lineinfile:
path: /usr/local/docker-container/{{ instance_name }}/.env
regexp: "^{{ item.key }}=.*$"
line: "{{ item.key }}={{ item.value }}"
backrefs: no # yes enables capture groups
# dict refers to new untracked .env copied from .env.example
# https://github.com/OpenSemanticLab/docker-compose-osl-wiki/blob/main/.example.env
# add or change valid key-value pairs to your needs and set vars in inventory.yml
with_dict:
MYSQL_ROOT_PASSWORD: "{{ admin_password }}"
MW_DB_PASS: "{{ admin_password }}"
MW_ADMIN_PASS: "{{ admin_password }}"
MW_SITE_SERVER: "https://{{ domain }}"
DRAWIO_SERVER: "https://drawio.{{ domain }}"
GRAPHDB_SERVER: "https://graph.{{ domain }}"
- name: Replace multiline values by key dict in .env file
ansible.builtin.replace:
path: /usr/local/docker-container/{{ instance_name }}/.env
# matches key="value" or key=value or key="\nvalue\n"
# but does not ensure existence of key
regexp: '{{ item.key }}=\"[^\"]*\"|{{ item.key }}=[^\n]*$'
replace: "{{ item.key }}={{ item.value }}"
with_dict:
MW_PAGE_PACKAGES: "{{ packages }}"
- name: Copy Compose Override Caddy
ansible.builtin.copy:
src: /usr/local/docker-container/{{ instance_name }}/docker-compose.caddy.example.override.yml
dest: /usr/local/docker-container/{{ instance_name }}/docker-compose.override.yml
remote_src: yes
owner: "{{ ansible_user }}"
mode: 0644
force: yes
- name: Deploy Compose Open Semantic World (OSW)
community.docker.docker_compose:
project_src: /usr/local/docker-container/{{ instance_name }}
pull: true
state: present
register: osw
- name: Wait until HTTP status is 200
uri:
url: 'https://{{ domain }}'
return_content: yes
validate_certs: yes
status_code:
- 200
until: uri_output.status == 200
delay: 10 # every 10 seconds
retries: 60 # total 10 min
register: uri_output
- name: Display OSW Domain
debug:
msg: "OSW has been deployed successfully, visit: https://{{ domain }}"
failed_when: uri_output.status != 200
# End: Deploy Open Semantic World (OSW)