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