997b1e9c91b1615be019f59ce49eb6cb39b5ed33
[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: true
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_user_state }}"
24   tags:
25     - nomad-conf-user
26
27 - name: Conf - Add Nomad user
28   user:
29     name: "{{ nomad_user }}"
30     group: "{{ nomad_group }}"
31     state: "{{ nomad_group_state }}"
32     system: true
33   tags:
34     - nomad-conf-user
35
36 - name: Inst - Clean Nomad
37   file:
38     path: "{{ nomad_inst_dir }}/nomad"
39     state: "absent"
40   tags:
41     - nomad-inst-package
42
43 - name: Inst - Download Nomad
44   get_url:
45     url: "{{ nomad_zip_url }}"
46     dest: "{{ nomad_inst_dir }}/{{ nomad_pkg }}"
47   tags:
48     - nomad-inst-package
49
50 - name: Inst - Unarchive Nomad
51   unarchive:
52     src: "{{ nomad_inst_dir }}/{{ nomad_pkg }}"
53     dest: "{{ nomad_inst_dir }}/"
54     creates: "{{ nomad_inst_dir }}/nomad"
55     remote_src: true
56   tags:
57     - nomad-inst-package
58
59 - name: Inst - Nomad
60   copy:
61     src: "{{ nomad_inst_dir }}/nomad"
62     dest: "{{ nomad_bin_dir }}"
63     owner: "{{ nomad_user }}"
64     group: "{{ nomad_group }}"
65     force: true
66     mode: 0755
67     remote_src: true
68   tags:
69     - nomad-inst-package
70
71 - name: Conf - Create Directories "{{ nomad_data_dir }}"
72   file:
73     dest: "{{ nomad_data_dir }}"
74     state: directory
75     owner: "{{ nomad_user }}"
76     group: "{{ nomad_group }}"
77   tags:
78     - nomad-conf
79
80 - name: Conf - Create Directories "{{ nomad_ssl_dir }}"
81   file:
82     dest: "{{ nomad_ssl_dir }}"
83     state: directory
84     owner: "{{ nomad_user }}"
85     group: "{{ nomad_group }}"
86   tags:
87     - nomad-conf
88
89 - name: Conf - Create Config Directory
90   file:
91     dest: "{{ nomad_config_dir }}"
92     state: directory
93     owner: "{{ nomad_user }}"
94     group: "{{ nomad_group }}"
95     mode: 0755
96   tags:
97     - nomad-conf
98
99 - name: Conf - Base Configuration
100   template:
101     src: base.hcl.j2
102     dest: "{{ nomad_config_dir }}/base.hcl"
103     owner: "{{ nomad_user }}"
104     group: "{{ nomad_group }}"
105     mode: 0644
106   tags:
107     - nomad-conf
108
109 - name: Conf - Server Configuration
110   template:
111     src: server.hcl.j2
112     dest: "{{ nomad_config_dir }}/server.hcl"
113     owner: "{{ nomad_user }}"
114     group: "{{ nomad_group }}"
115     mode: 0644
116   when:
117     - nomad_node_server | bool
118   tags:
119     - nomad-conf
120
121 - name: Conf - Client Configuration
122   template:
123     src: client.hcl.j2
124     dest: "{{ nomad_config_dir }}/client.hcl"
125     owner: "{{ nomad_user }}"
126     group: "{{ nomad_group }}"
127     mode: 0644
128   when:
129     - nomad_node_client | bool
130   tags:
131     - nomad-conf
132
133 - name: Conf - TLS Configuration
134   template:
135     src: tls.hcl.j2
136     dest: "{{ nomad_config_dir }}/tls.hcl"
137     owner: "{{ nomad_user }}"
138     group: "{{ nomad_group }}"
139     mode: 0644
140   tags:
141     - nomad-conf
142
143 - name: Conf - Telemetry Configuration
144   template:
145     src: telemetry.hcl.j2
146     dest: "{{ nomad_config_dir }}/telemetry.hcl"
147     owner: "{{ nomad_user }}"
148     group: "{{ nomad_group }}"
149     mode: 0644
150   tags:
151     - nomad-conf
152
153 - name: Conf - Consul Configuration
154   template:
155     src: consul.hcl.j2
156     dest: "{{ nomad_config_dir }}/consul.hcl"
157     owner: "{{ nomad_user }}"
158     group: "{{ nomad_group }}"
159     mode: 0644
160   tags:
161     - nomad-conf
162
163 - name: Conf - Copy Certificates And Keys
164   copy:
165     content: "{{ item.src }}"
166     dest: "{{ item.dest }}"
167     owner: "{{ nomad_user }}"
168     group: "{{ nomad_group }}"
169     mode: 0600
170   no_log: true
171   loop: "{{ nomad_certificates | flatten(levels=1) }}"
172   tags:
173     - nomad-conf
174
175 - name: Conf - System.d Script
176   template:
177     src: "nomad_systemd.service.j2"
178     dest: "/lib/systemd/system/nomad.service"
179     owner: "root"
180     group: "root"
181     mode: 0644
182   notify:
183     - "Restart Nomad"
184   tags:
185     - nomad-conf
186
187 - meta: flush_handlers