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