-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaybook.yaml
More file actions
217 lines (192 loc) · 6.09 KB
/
playbook.yaml
File metadata and controls
217 lines (192 loc) · 6.09 KB
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
- name: "Create license manager user and group"
hosts:
- pouta_license_server
become: true
vars:
download_url: "https://ssd.mathworks.com/supportfiles/downloads/R2026a/license_manager/R2026a/daemons/glnxa64/mathworks_network_license_manager_glnxa64.zip"
download_checksum: "sha256:2c93c8a9c511f25a5ab1ffef4549243f26e7290f797ef9f4a4c6630cdb3ceddf"
dir_lm: "/license/matlab/lm/R2026a"
dir_license: "/license/matlab/files"
license_file: "{{ dir_license }}/license.lic"
options_file: "{{ dir_license }}/license.opt"
log_file: "{{ dir_license }}/license.log"
license_server_port: 27000
license_manager_port: 27001
tasks:
- name: "Upgrade all packages"
ansible.builtin.apt:
upgrade: yes
update_cache: yes
cache_valid_time: 3600
- name: "Install unzip"
ansible.builtin.apt:
name:
- unzip
state: present
install_recommends: no
- name: "Firewall config"
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_port: "{{ item }}"
jump: ACCEPT
state: present
loop:
- 27000
- 27001
- name: "Create non-standard tmp location for legacy FlexLM"
ansible.builtin.file:
src: /tmp
dest: /usr/tmp
state: link
- name: "Create license directory"
ansible.builtin.file:
path: "/license"
state: directory
mode: "u=rwx,go=rx"
- name: Create group lmadmin
ansible.builtin.group:
name: lmadmin
state: present
- name: Create user lmmatlab
ansible.builtin.user:
name: lmmatlab
group: lmadmin
state: present
- name: "Create license manager directory"
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "u=rwx,go=rx"
owner: lmmatlab
group: lmadmin
loop:
- "{{ dir_lm }}"
- "{{ dir_lm }}/bin"
- name: "Download matlab license manager"
ansible.builtin.get_url:
url: "{{ download_url }}"
dest: "{{ dir_lm }}/mlm.zip"
checksum: "{{ download_checksum }}"
mode: "u=rw,go=r"
owner: lmmatlab
group: lmadmin
- name: "Extract the archive"
ansible.builtin.unarchive:
src: "{{ dir_lm }}/mlm.zip"
dest: "{{ dir_lm }}"
remote_src: true
mode: "u=rwX,go=rX"
owner: lmmatlab
group: lmadmin
- name: "lm_hostid command"
ansible.builtin.copy:
content: |
#!/usr/bin/env bash
{{ dir_lm }}/etc/glnxa64/lmutil lmhostid -n
dest: "{{ dir_lm }}/bin/lm_hostid"
mode: "u=rwx,go=rx"
owner: lmmatlab
group: lmadmin
- name: "lm_status command"
ansible.builtin.copy:
content: |
#!/usr/bin/env bash
{{ dir_lm }}/etc/glnxa64/lmutil lmstat -a -c "{{ license_file }}"
dest: "{{ dir_lm }}/bin/lm_status"
mode: "u=rwx,go=rx"
owner: lmmatlab
group: lmadmin
- name: "lm_reload command"
ansible.builtin.copy:
content: |
#!/usr/bin/env bash
{{ dir_lm }}/etc/glnxa64/lmutil lmreread -c "{{ license_file }}" -vendor MLM
dest: "{{ dir_lm }}/bin/lm_reload"
mode: "u=rwx,go=rx"
owner: lmmatlab
group: lmadmin
- name: "lm_start command"
ansible.builtin.copy:
content: |
#!/usr/bin/env bash
{{ dir_lm }}/etc/glnxa64/lmgrd -c "{{ license_file }}" -l "+{{ log_file }}" -2 -p lmdown
dest: "{{ dir_lm }}/bin/lm_start"
mode: "u=rwx,go=rx"
owner: lmmatlab
group: lmadmin
- name: "lm_stop command"
ansible.builtin.copy:
content: |
#!/usr/bin/env bash
kill -9 "$(pidof "{{ dir_lm }}/etc/glnxa64/lmgrd")" "$(pidof "{{ dir_lm }}/etc/glnxa64/MLM")"
dest: "{{ dir_lm }}/bin/lm_stop"
mode: "u=rwx,go=rx"
owner: lmmatlab
group: lmadmin
- name: "Create license file directory"
ansible.builtin.file:
path: "{{ dir_license }}"
state: directory
mode: "u=rwx,go=rx"
owner: lmmatlab
group: lmadmin
- name: "Retrieve hostid used by license.lic.j2"
command: '"{{ dir_lm }}/bin/lm_hostid"'
register: hostid
- name: "Print hostid"
ansible.builtin.debug:
msg: "hostid: {{ hostid.stdout }}"
- name: "Install license file"
ansible.builtin.copy:
content: |
SERVER this_host {{ hostid.stdout }} {{ license_server_port }}
VENDOR MLM {{ dir_lm }}/etc/glnxa64/MLM {{ options_file }} port={{ license_manager_port }}
# MATLAB license contents
dest: "{{ license_file }}"
mode: "u=rw,go=r"
owner: lmmatlab
group: lmadmin
backup: yes
- name: "Install options file"
ansible.builtin.copy:
content: |
# Allow specific users to use the license.
INCLUDEALL USER nobody
# Disallow anyony else but the allowed users from using the licese.
EXCLUDEALL USER_GROUP EVERYONE
dest: "{{ options_file }}"
mode: "u=rw,go=r"
owner: lmmatlab
group: lmadmin
backup: yes
- name: "Touch log file without modifying it"
ansible.builtin.file:
path: "{{ log_file }}"
state: "touch"
mode: "u=rw,go=r"
modification_time: "preserve"
access_time: "preserve"
owner: lmmatlab
group: lmadmin
- name: "Create systemd service"
ansible.builtin.copy:
content: |
[Unit]
Description=MATLAB License Service
After=network.target
[Service]
Type=forking
User=lmmatlab
ExecStart={{ dir_lm}}/bin/lm_start
Restart=on-failure
[Install]
WantedBy=multi-user.target
dest: "/etc/systemd/system/lm_matlab.service"
mode: "u=rw,g=r,o=r"
- name: "Reload changes, then enable and start service"
ansible.builtin.systemd:
name: "lm_matlab"
state: "started"
enabled: true
daemon_reload: true