forked from rciam/rciam-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiservers.yml
139 lines (124 loc) · 4.91 KB
/
apiservers.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
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
# file: apiservers.yml
#
---
- name: Deploy API servers
hosts: api
roles:
- role: geerlingguy.nodejs
become: true
- role: Oefenweb.yarn
become: true
vars:
nodejs_version: "10.x"
nodejs_npm_global_packages:
- bunyan
- pm2
rciam_api:
name: vomembers-api
port: 8080
path: /srv/comanage-registry-simple-membership-api/VoMembers/v1
repo_url: https://github.com/grnet/comanage-registry-simple-membership-api.git
repo_version: devel
user:
name: rciam-comanage-registry-api
group: rciam-comanage-registry-api
gecos: "RCIAM COmanage Registry API Server,,,"
shell: /bin/bash
home: /srv/comanage-registry-simple-membership-api
tasks:
- name: Ensure RCIAM API dependencies are installed
become: true
ansible.builtin.apt:
name: git
state: present
install_recommends: false
update_cache: true
cache_valid_time: 86400
- name: Ensure RCIAM COmanage Registry API group exists
become: true
ansible.builtin.group:
name: "{{ rciam_api.user.group }}"
system: true
- name: Ensure RCIAM COmanage Registry API user exists
become: true
ansible.builtin.user:
name: "{{ rciam_api.user.name }}"
groups: "{{ rciam_api.user.group }}"
comment: "{{ rciam_api.user.gecos }}"
shell: "{{ rciam_api.user.shell }}"
home: "{{ rciam_api.user.home }}"
system: true
create_home: true
skeleton: "/empty"
- name: Ensure RCIAM COmanage Registry API code checkout directory exists
become: true
ansible.builtin.file:
path: "{{ rciam_api.path }}"
owner: "{{ rciam_api.user.name }}"
group: "{{ rciam_api.user.group }}"
state: directory
mode: "0775"
- name: Ensure RCIAM COmanage Registry API code checkout is up-to-date
become: true
become_user: "{{ rciam_api.user.name }}"
ansible.builtin.git:
repo: "{{ rciam_api.repo_url }}"
dest: "{{ rciam_api.path }}"
version: "{{ rciam_api.repo_version }}"
notify: Restart RCIAM COmanage Registry API processes
# TODO- name: Ensure RCIAM COmanage Registry API current symlink to code checkout directory exists
# file:
# src: "{{ rciam_api.path }}"
# path: "{{ rciam_api.path }}/current"
# owner: "{{ rciam_api.user.name }}"
# group: "{{ rciam_api.user.group }}"
# state: link
# become: yes
- name: Ensure RCIAM COmanage Registry API is configured
become: true
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/comanage-registry-simple-membership-api/settings.js.j2"
dest: "{{ rciam_api.path }}/settings.js"
owner: "{{ rciam_api.user.name }}"
group: "{{ rciam_api.user.group }}"
mode: "0400"
backup: true
notify: Restart RCIAM COmanage Registry API processes
- name: Ensure RCIAM COmanage Registry API packages are installed
become: true
become_user: "{{ rciam_api.user.name }}"
community.general.yarn:
path: "{{ rciam_api.path }}"
production: true
handlers:
- name: Delete existing RCIAM COmanage Registry API pm2 processes if running
become: true
become_user: "{{ rciam_api.user.name }}"
ansible.builtin.command: # noqa: no-changed-when
cmd: "/usr/local/lib/npm/bin/pm2 delete {{ rciam_api.name }}"
chdir: "{{ rciam_api.path }}"
ignore_errors: true # noqa: ignore-errors
# failed_when: # Add acceptable failure conditions
listen: Restart RCIAM COmanage Registry API processes
- name: Ensure RCIAM COmanage Registry API pm2 processes are running
become: true
become_user: "{{ rciam_api.user.name }}"
ansible.builtin.command: # noqa: no-changed-when
cmd: "/usr/local/lib/npm/bin/pm2 start server.js -i 2 --name {{ rciam_api.name }}"
chdir: "{{ rciam_api.path }}"
# changed_when: # Add acceptable change conditions to ensure idempotency
listen: Restart RCIAM COmanage Registry API processes
- name: Ensure RCIAM COmanage Registry API init script exists
become: true
ansible.builtin.command: # noqa: no-changed-when
cmd: "/usr/local/lib/npm/lib/node_modules/pm2/bin/pm2 startup systemd -u {{ rciam_api.user.name }} --hp {{ rciam_api.user.home }}"
# changed_when: # Add acceptable change conditions to ensure idempotency
listen: Restart RCIAM COmanage Registry API processes
- name: Ensure RCIAM COmanage Registry API process list is saved
become: true
become_user: "{{ rciam_api.user.name }}"
ansible.builtin.command: # noqa: no-changed-when
cmd: "/usr/local/lib/npm/lib/node_modules/pm2/bin/pm2 save"
chdir: "{{ rciam_api.path }}"
listen: Restart RCIAM COmanage Registry API processes
# changed_when: # Add acceptable change conditions to ensure idempotency