5b323054d49a8a55cc1a6c304d14e9009271ddf7
[csit.git] / resources / tools / testbed-setup / ansible / roles / nomad / tasks / main.yaml
1 ---
2 # file: roles/nomad/tasks/main.yaml
3
4 - Name: Update package cache (apt)
5   apt:
6     update_cache: yes
7     cache_valid_time: 3600
8   when:
9     - ansible_distribution|lower == 'ubuntu'
10
11 - name: Inst - Prerequisites
12   package:
13     name: "{{ packages | flatten(levels=1) }}"
14     state: latest
15   tags:
16     - nomad-inst-prerequisites
17
18 - name: Conf - Add Nomad Group
19   group:
20     name: "{{ nomad_group }}"
21     state: "{{ nomad_group_state }}"
22   when:
23     - nomad_manage_group | bool
24   tags:
25     - nomad-conf-user
26
27 - name: Conf - Add Nomad user
28   user:
29     name: "{{ nomad_user }}"
30     group: "{{ nomad_group }}"
31     groups: "{{ nomad_user_groups }}"
32     state: "{{ nomad_user_state }}"
33     system: true
34   when:
35     - nomad_manage_user | bool
36   tags:
37     - nomad-conf-user
38
39 - name: Inst - Clean Nomad
40   file:
41     path: "{{ nomad_inst_dir }}/nomad"
42     state: "absent"
43   tags:
44     - nomad-inst-package
45
46 - name: Inst - Download Nomad
47   get_url:
48     url: "{{ nomad_zip_url }}"
49     dest: "{{ nomad_inst_dir }}/{{ nomad_pkg }}"
50   tags:
51     - nomad-inst-package
52
53 - name: Inst - Unarchive Nomad
54   unarchive:
55     src: "{{ nomad_inst_dir }}/{{ nomad_pkg }}"
56     dest: "{{ nomad_inst_dir }}/"
57     creates: "{{ nomad_inst_dir }}/nomad"
58     remote_src: true
59   tags:
60     - nomad-inst-package
61
62 - name: Inst - Nomad
63   copy:
64     src: "{{ nomad_inst_dir }}/nomad"
65     dest: "{{ nomad_bin_dir }}"
66     owner: "{{ nomad_user }}"
67     group: "{{ nomad_group }}"
68     force: true
69     mode: 0755
70     remote_src: true
71   tags:
72     - nomad-inst-package
73
74 - name: Conf - Create Directories "{{ nomad_data_dir }}"
75   file:
76     dest: "{{ nomad_data_dir }}"
77     state: directory
78     owner: "{{ nomad_user }}"
79     group: "{{ nomad_group }}"
80   tags:
81     - nomad-conf
82
83 - name: Conf - Create Directories "{{ nomad_ssl_dir }}"
84   file:
85     dest: "{{ nomad_ssl_dir }}"
86     state: directory
87     owner: "{{ nomad_user }}"
88     group: "{{ nomad_group }}"
89   tags:
90     - nomad-conf
91
92 - name: Conf - Create Config Directory
93   file:
94     dest: "{{ nomad_config_dir }}"
95     state: directory
96     owner: "{{ nomad_user }}"
97     group: "{{ nomad_group }}"
98     mode: 0755
99   tags:
100     - nomad-conf
101
102 - name: Conf - Base Configuration
103   template:
104     src: base.hcl.j2
105     dest: "{{ nomad_config_dir }}/base.hcl"
106     owner: "{{ nomad_user }}"
107     group: "{{ nomad_group }}"
108     mode: 0644
109   tags:
110     - nomad-conf
111
112 - name: Conf - Server Configuration
113   template:
114     src: server.hcl.j2
115     dest: "{{ nomad_config_dir }}/server.hcl"
116     owner: "{{ nomad_user }}"
117     group: "{{ nomad_group }}"
118     mode: 0644
119   when:
120     - nomad_node_server | bool
121   tags:
122     - nomad-conf
123
124 - name: Conf - Client Configuration
125   template:
126     src: client.hcl.j2
127     dest: "{{ nomad_config_dir }}/client.hcl"
128     owner: "{{ nomad_user }}"
129     group: "{{ nomad_group }}"
130     mode: 0644
131   when:
132     - nomad_node_client | bool
133   tags:
134     - nomad-conf
135
136 - name: Conf - TLS Configuration
137   template:
138     src: tls.hcl.j2
139     dest: "{{ nomad_config_dir }}/tls.hcl"
140     owner: "{{ nomad_user }}"
141     group: "{{ nomad_group }}"
142     mode: 0644
143   tags:
144     - nomad-conf
145
146 - name: Conf - Telemetry Configuration
147   template:
148     src: telemetry.hcl.j2
149     dest: "{{ nomad_config_dir }}/telemetry.hcl"
150     owner: "{{ nomad_user }}"
151     group: "{{ nomad_group }}"
152     mode: 0644
153   tags:
154     - nomad-conf
155
156 - name: Conf - Custom Configuration
157   template:
158     src: custom.json.j2
159     dest: "{{ nomad_config_dir }}/custom.json"
160     owner: "{{ nomad_user }}"
161     group: "{{ nomad_group }}"
162     mode: 0644
163   when:
164     - nomad_config_custom is defined
165   tags:
166     - nomad-conf
167
168 - name: Conf - Copy Certificates And Keys
169   copy:
170     content: "{{ item.src }}"
171     dest: "{{ item.dest }}"
172     owner: "{{ nomad_user }}"
173     group: "{{ nomad_group }}"
174     mode: 0600
175   no_log: true
176   loop: "{{ nomad_certificates | flatten(levels=1) }}"
177   tags:
178     - nomad-conf
179
180 - name: Conf - System.d Script
181   template:
182     src: "nomad_systemd.service.j2"
183     dest: "/lib/systemd/system/nomad.service"
184     owner: "root"
185     group: "root"
186     mode: 0644
187 #  notify:
188 #    - "Restart Nomad"
189   tags:
190     - nomad-conf