feat(ansible): Migrate Ubuntu Jammy IV.
[csit.git] / fdio.infra.ansible / roles / nomad / tasks / main.yaml
1 ---
2 # file: tasks/main.yaml
3
4 - name: Inst - Update Repositories Cache
5   ansible.builtin.apt:
6     update_cache: true
7   when:
8     - ansible_os_family == 'Debian'
9   tags:
10     - nomad-inst-package
11
12 - name: Inst - Dependencies
13   ansible.builtin.apt:
14     name: "{{ packages | flatten(levels=1) }}"
15     state: "present"
16     cache_valid_time: 3600
17     install_recommends: false
18   when:
19     - ansible_os_family == 'Debian'
20   tags:
21     - nomad-inst-dependencies
22
23 - name: Conf - Add Nomad Group
24   ansible.builtin.group:
25     name: "{{ nomad_group }}"
26     state: "{{ nomad_user_state }}"
27   tags:
28     - nomad-conf-user
29
30 - name: Conf - Add Nomad user
31   ansible.builtin.user:
32     name: "{{ nomad_user }}"
33     group: "{{ nomad_group }}"
34     state: "{{ nomad_group_state }}"
35     system: true
36   tags:
37     - nomad-conf-user
38
39 - name: Inst - Download Nomad
40   ansible.builtin.get_url:
41     url: "{{ nomad_zip_url }}"
42     dest: "{{ nomad_inst_dir }}/{{ nomad_pkg }}"
43   tags:
44     - nomad-inst-package
45
46 - name: Inst - Clean Nomad
47   ansible.builtin.file:
48     path: "{{ nomad_inst_dir }}/nomad"
49     state: "absent"
50   when:
51     - nomad_force_update | bool
52   tags:
53     - nomad-inst-package
54
55 - name: Inst - Unarchive Nomad
56   ansible.builtin.unarchive:
57     src: "{{ nomad_inst_dir }}/{{ nomad_pkg }}"
58     dest: "{{ nomad_inst_dir }}/"
59     remote_src: true
60   tags:
61     - nomad-inst-package
62
63 - name: Inst - Nomad
64   ansible.builtin.copy:
65     src: "{{ nomad_inst_dir }}/nomad"
66     dest: "{{ nomad_bin_dir }}"
67     owner: "{{ nomad_user }}"
68     group: "{{ nomad_group }}"
69     force: true
70     mode: 0755
71     remote_src: true
72   tags:
73     - nomad-inst-package
74
75 - name: Conf - Create Directories "{{ nomad_data_dir }}"
76   ansible.builtin.file:
77     dest: "{{ nomad_data_dir }}"
78     state: directory
79     owner: "{{ nomad_user }}"
80     group: "{{ nomad_group }}"
81     mode: 0755
82   tags:
83     - nomad-conf
84
85 - name: Conf - Create Directories "{{ nomad_ssl_dir }}"
86   ansible.builtin.file:
87     dest: "{{ nomad_ssl_dir }}"
88     state: directory
89     owner: "{{ nomad_user }}"
90     group: "{{ nomad_group }}"
91     mode: 0755
92   tags:
93     - nomad-conf
94
95 - name: Conf - Create Config Directory
96   ansible.builtin.file:
97     dest: "{{ nomad_config_dir }}"
98     state: directory
99     owner: "{{ nomad_user }}"
100     group: "{{ nomad_group }}"
101     mode: 0755
102   tags:
103     - nomad-conf
104
105 - name: Conf - Base Configuration
106   ansible.builtin.template:
107     src: base.hcl.j2
108     dest: "{{ nomad_config_dir }}/base.hcl"
109     owner: "{{ nomad_user }}"
110     group: "{{ nomad_group }}"
111     mode: 0644
112   tags:
113     - nomad-conf
114
115 - name: Conf - Server Configuration
116   ansible.builtin.template:
117     src: server.hcl.j2
118     dest: "{{ nomad_config_dir }}/server.hcl"
119     owner: "{{ nomad_user }}"
120     group: "{{ nomad_group }}"
121     mode: 0644
122   when:
123     - nomad_node_server | bool
124   tags:
125     - nomad-conf
126
127 - name: Conf - Client Configuration
128   ansible.builtin.template:
129     src: client.hcl.j2
130     dest: "{{ nomad_config_dir }}/client.hcl"
131     owner: "{{ nomad_user }}"
132     group: "{{ nomad_group }}"
133     mode: 0644
134   when:
135     - nomad_node_client | bool
136   tags:
137     - nomad-conf
138
139 - name: Conf - TLS Configuration
140   ansible.builtin.template:
141     src: tls.hcl.j2
142     dest: "{{ nomad_config_dir }}/tls.hcl"
143     owner: "{{ nomad_user }}"
144     group: "{{ nomad_group }}"
145     mode: 0644
146   tags:
147     - nomad-conf
148
149 - name: Conf - Telemetry Configuration
150   ansible.builtin.template:
151     src: telemetry.hcl.j2
152     dest: "{{ nomad_config_dir }}/telemetry.hcl"
153     owner: "{{ nomad_user }}"
154     group: "{{ nomad_group }}"
155     mode: 0644
156   tags:
157     - nomad-conf
158
159 - name: Conf - Consul Configuration
160   ansible.builtin.template:
161     src: consul.hcl.j2
162     dest: "{{ nomad_config_dir }}/consul.hcl"
163     owner: "{{ nomad_user }}"
164     group: "{{ nomad_group }}"
165     mode: 0644
166   tags:
167     - nomad-conf
168
169 - name: Conf - Copy Certificates And Keys
170   ansible.builtin.copy:
171     content: "{{ item.src }}"
172     dest: "{{ item.dest }}"
173     owner: "{{ nomad_user }}"
174     group: "{{ nomad_group }}"
175     mode: 0600
176   no_log: true
177   loop: "{{ nomad_certificates | flatten(levels=1) }}"
178   when:
179     - nomad_certificates is defined
180   tags:
181     - nomad-conf
182
183 - name: Conf - Nomad CLI Environment Variables
184   ansible.builtin.lineinfile:
185     path: "/etc/profile.d/nomad.sh"
186     line: "{{ item }}"
187     create: true
188   loop:
189     - "export NOMAD_ADDR=http://nomad.service.consul:4646"
190     - "export NOMAD_CACERT={{ nomad_ca_file }}"
191 #    - "export NOMAD_CLIENT_CERT={{ nomad_cli_cert_file }}"
192 #    - "export NOMAD_CLIENT_KEY={{ nomad_cli_key_file }}"
193   tags:
194     - nomad-conf
195
196 - name: Conf - System.d Script
197   ansible.builtin.template:
198     src: "nomad_systemd.service.j2"
199     dest: "/lib/systemd/system/nomad.service"
200     owner: "root"
201     group: "root"
202     mode: 0644
203   notify:
204     - "Restart Nomad"
205   when:
206     - nomad_service_mgr == "systemd"
207   tags:
208     - nomad-conf
209
210 - name: Meta - Flush handlers
211   ansible.builtin.meta: flush_handlers