Skip to content

Commit c8919d0

Browse files
Upgrade nomad, podman driver. Added many features. (#131)
* Update main.yml * Added host networks * Added README and exmaple for host networks * Fixed README for host nets * Upgraded nomad_version * Updated readme * Update README.md * Update client.hcl.j2 * Added cni support * Added cni dir creation * Fixed archiving * updated readme with cni * Updated copy * Added tls * Fixed a bug * Fixed a bug * Fixed a bug * Added tls copy support * Added readme * Minor formatting * Added new line at end of defaults * Fixed multiple vars * Fixed vars * Fixed vars bug giving appended path * Updated podman to 0.3.0 * Added tls consul support * Added readme * Added ssl consul Co-authored-by: Hemanth Bollamreddi <hbollamreddi@vmware.com>
1 parent 37bde5e commit c8919d0

File tree

7 files changed

+248
-14
lines changed

7 files changed

+248
-14
lines changed

README.md

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The role defines most of its variables in `defaults/main.yml`:
4848
### `nomad_version`
4949

5050
- Nomad version to install
51-
- Default value: **0.12.0**
51+
- Default value: **1.1.1**
5252

5353
### `nomad_architecture_map`
5454

@@ -339,6 +339,22 @@ nomad_host_volumes:
339339
read_only: false
340340
```
341341
342+
### `nomad_host_networks`
343+
344+
- List host_network is used to make different networks available to jobs instead of selecting a default interface. This is very useful especially in case of multiple nics.
345+
- Default value: **[]**
346+
- Example:
347+
348+
```yaml
349+
nomad_host_networks:
350+
- name: public
351+
cidr: 100.101.102.103/24
352+
reserved_ports: 22,80
353+
- name: private
354+
interface: eth0
355+
reserved_ports: 443
356+
```
357+
342358
### `nomad_options`
343359

344360
- Driver options
@@ -392,6 +408,11 @@ nomad_host_volumes:
392408
- Installs the podman plugin
393409
- Default value: **false**
394410

411+
### `nomad_cni_enable`
412+
413+
- Installs the cni plugins
414+
- Default value: **false**
415+
395416
### `nomad_docker_enable`
396417

397418
- Install Docker subsystem on nodes?
@@ -446,9 +467,29 @@ in many Ansible versions, so this feature might not always work.
446467

447468
### `nomad_consul_address`
448469

449-
- The address of your consul API, use it in combination with nomad_use_consul=True
470+
- The address of your consul API, use it in combination with nomad_use_consul=True. If you want to use https, use `nomad_consul_ssl`. Do NOT append https.
450471
- Default value: **localhost:8500**
451472

473+
### `nomad_consul_ssl`
474+
475+
- If `true` then uses https.
476+
- Default value: **false**
477+
478+
### `nomad_consul_ca_file`
479+
480+
- Public key of consul CA, use in combination with `nomad_consul_cert_file` and `nomad_consul_key_file`.
481+
- Default value: ""
482+
483+
### `nomad_consul_cert_file`
484+
485+
- The public key which can be used to access consul.
486+
- Default value: ""
487+
488+
### `nomad_consul_key_file`
489+
490+
- The private key counterpart of `nomad_consul_cert_file`.
491+
- Default value: ""
492+
452493
### `nomad_consul_servers_service_name`
453494

454495
- The name of the consul service for your nomad servers
@@ -564,20 +605,35 @@ in many Ansible versions, so this feature might not always work.
564605
- Enable TLS
565606
- Default value: false
566607

608+
### `nomad_tls_copy_keys`: false
609+
610+
- Whether to copy certs from local machine (controller).
611+
- Default value: false
612+
613+
### `nomad_tls_files_remote_src`
614+
615+
- Whether to copy certs from remote machine itself.
616+
- Default value: false
617+
618+
### `nomad_tls_dir`
619+
620+
- The remote dir where the certs are stored.
621+
- Default value: `/etc/nomad/ssl`
622+
567623
### `nomad_ca_file`
568624

569625
- Use a ca for tls connection, nomad_cert_file and nomad_key_file are needed
570-
- Default value: **""**
626+
- Default value: ca.cert
571627

572628
### `nomad_cert_file`
573629

574630
- Use a certificate for tls connection, nomad_ca_file and nomad_key_file are needed
575-
- Default value: **""**
631+
- Default value: server.crt
576632

577633
### `nomad_key_file`
578634

579635
- Use a key for tls connection, nomad_cert_file and nomad_key_file are needed
580-
- Default value: **""**
636+
- Default value: server.key
581637

582638
### `nomad_rpc_upgrade_mode`
583639

defaults/main.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ nomad_skip_ensure_all_hosts: "{{ lookup('env','NOMAD_SKIP_ENSURE_ALL_HOSTS') | d
3232
nomad_allow_purge_config: "{{ lookup('env','NOMAD_ALLOW_PURGE_CONFIG') | default('false', true) }}"
3333

3434
### Package
35-
nomad_version: "{{ lookup('env','NOMAD_VERSION') | default('1.0.4', true) }}"
35+
nomad_version: "{{ lookup('env','NOMAD_VERSION') | default('1.1.1', true) }}"
3636
nomad_architecture_map:
3737
amd64: amd64
3838
x86_64: amd64
@@ -45,7 +45,7 @@ nomad_pkg: "nomad_{{ nomad_version }}_linux_{{nomad_architecture}}.zip"
4545
nomad_zip_url: "https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version }}_linux_{{nomad_architecture}}.zip"
4646
nomad_checksum_file_url: "https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version}}_SHA256SUMS"
4747
nomad_podman_enable: false
48-
nomad_podman_version: "{{ lookup('env','NOMAD_PODMAN_VERSION') | default('0.1.0', true) }}"
48+
nomad_podman_version: "{{ lookup('env','NOMAD_PODMAN_VERSION') | default('0.3.0', true) }}"
4949
nomad_podman_pkg: "nomad-driver-podman_{{ nomad_podman_version }}_linux_{{nomad_architecture}}.zip"
5050
nomad_podman_url: "https://releases.hashicorp.com/nomad-driver-podman/{{ nomad_podman_version }}"
5151
nomad_podman_zip_url: "{{ nomad_podman_url }}/{{ nomad_podman_pkg }}"
@@ -114,6 +114,7 @@ nomad_reserved:
114114
disk: "{{ nomad_reserved_disk | default('0', true) }}"
115115
ports: "{{ nomad_reserved_ports | default('22', true) }}"
116116
nomad_host_volumes: []
117+
nomad_host_networks: []
117118
nomad_options: {}
118119
nomad_meta: {}
119120
nomad_bootstrap_expect: "{{ nomad_servers | count or 3 }}"
@@ -150,6 +151,10 @@ nomad_gather_server_facts: false
150151
### Consul
151152
nomad_use_consul: false
152153
nomad_consul_address: "localhost:8500"
154+
nomad_consul_ssl: false
155+
nomad_consul_ca_file: ""
156+
nomad_consul_cert_file: ""
157+
nomad_consul_key_file: ""
153158
nomad_consul_token: ""
154159
nomad_consul_servers_service_name: "nomad-servers"
155160
nomad_consul_clients_service_name: "nomad-clients"
@@ -180,11 +185,14 @@ nomad_vault_namespace: ""
180185
nomad_docker_enable: "{{ lookup('env','NOMAD_DOCKER_ENABLE') | default('false', true) }}"
181186
nomad_docker_dmsetup: true
182187

183-
### Tls
188+
### TlS
184189
nomad_tls_enable: false
185-
nomad_ca_file: ""
186-
nomad_cert_file: ""
187-
nomad_key_file: ""
190+
nomad_tls_copy_keys: false
191+
nomad_tls_files_remote_src: false
192+
nomad_tls_dir: "{{ lookup('env','NOMAD_TLS_DIR') | default('/etc/nomad/ssl', true) }}"
193+
nomad_ca_file: "{{ lookup('env','NOMAD_CA_FILE') | default('ca.crt', true) }}"
194+
nomad_cert_file: "{{ lookup('env','NOMAD_CERT_FILE') | default('server.crt', true) }}"
195+
nomad_key_file: "{{ lookup('env','NOMAD_KEY_FILE') | default('server.key', true) }}"
188196
nomad_rpc_upgrade_mode: false
189197
nomad_verify_server_hostname: true
190198
nomad_verify_https_client: true
@@ -194,3 +202,12 @@ nomad_autopilot_cleanup_dead_servers: true
194202
nomad_autopilot_last_contact_threshold: "200ms"
195203
nomad_autopilot_max_trailing_logs: 250
196204
nomad_autopilot_server_stabilization_time: "10s"
205+
206+
### CNI
207+
nomad_cni_enable: false
208+
nomad_cni_dir: "/opt/cni/bin"
209+
nomad_cni_version: "{{ lookup('env','NOMAD_CNI_VERSION') | default('0.9.1', true) }}"
210+
nomad_cni_pkg: "cni-plugins-linux-{{nomad_architecture}}-v{{ nomad_cni_version }}.tgz"
211+
nomad_cni_url: "https://github.com/containernetworking/plugins/releases/download/v{{ nomad_cni_version }}"
212+
nomad_cni_zip_url: "{{ nomad_cni_url }}/{{ nomad_cni_pkg }}"
213+
nomad_cni_checksum_file_url: "{{ nomad_cni_zip_url }}.sha256"

tasks/cni.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
# File: cni_plugin.yml - package installation tasks for Nomad CNI Plugin
3+
4+
- name: Create cni directory
5+
file:
6+
dest: "{{ nomad_cni_dir }}"
7+
state: directory
8+
owner: "{{ nomad_user }}"
9+
group: "{{ nomad_group }}"
10+
11+
- name: Check CNI package checksum file
12+
stat:
13+
path: "{{ role_path }}/files/nomad_cni_{{ nomad_cni_version }}_SHA256SUMS"
14+
become: false
15+
run_once: true
16+
tags: installation
17+
register: nomad_cni_checksum
18+
delegate_to: 127.0.0.1
19+
20+
- name: Get Nomad CNI package checksum file
21+
get_url:
22+
url: "{{ nomad_cni_checksum_file_url }}"
23+
dest: "{{ role_path }}/files/nomad_cni_{{ nomad_cni_version }}_SHA256SUMS"
24+
become: false
25+
run_once: true
26+
tags: installation
27+
when: not nomad_cni_checksum.stat.exists
28+
delegate_to: 127.0.0.1
29+
30+
- name: Get Nomad CNI package checksum
31+
shell: |
32+
set -o pipefail
33+
grep "{{ nomad_cni_pkg }}" "{{ role_path }}/files/nomad_cni_{{ nomad_cni_version }}_SHA256SUMS" | awk '{print $1}'
34+
args:
35+
executable: /bin/bash
36+
become: false
37+
register: nomad_cni_sha256
38+
tags: installation
39+
delegate_to: 127.0.0.1
40+
41+
- name: Check Nomad CNI package file
42+
stat:
43+
path: "{{ role_path }}/files/{{ nomad_cni_pkg }}"
44+
become: false
45+
register: nomad_cni_package
46+
delegate_to: 127.0.0.1
47+
48+
- name: Download Nomad CNI
49+
get_url:
50+
url: "{{ nomad_cni_zip_url }}"
51+
dest: "{{ role_path }}/files/{{ nomad_cni_pkg }}"
52+
checksum: "sha256:{{ nomad_cni_sha256.stdout }}"
53+
timeout: "42"
54+
become: false
55+
tags: installation
56+
delegate_to: 127.0.0.1
57+
when: not nomad_cni_package.stat.exists
58+
59+
- name: Create Temporary Directory for Extraction
60+
tempfile:
61+
state: directory
62+
prefix: ansible-nomad.
63+
become: false
64+
register: install_temp
65+
tags: installation
66+
delegate_to: 127.0.0.1
67+
68+
- name: Unarchive Nomad CNI
69+
unarchive:
70+
src: "{{ role_path }}/files/{{ nomad_cni_pkg }}"
71+
dest: "{{ install_temp.path }}/"
72+
creates: "{{ install_temp.path }}/bridge"
73+
become: false
74+
tags: installation
75+
delegate_to: 127.0.0.1
76+
77+
- name: Install Nomad CNI
78+
copy:
79+
src: "{{ item }}"
80+
dest: "{{ nomad_cni_dir }}"
81+
owner: "{{ nomad_user }}"
82+
group: "{{ nomad_group }}"
83+
mode: 0755
84+
with_fileglob:
85+
- "{{ install_temp.path }}/*"
86+
tags: installation
87+
notify: restart nomad
88+
89+
- name: Cleanup
90+
file:
91+
path: "{{ install_temp.path }}"
92+
state: "absent"
93+
become: false
94+
tags: installation
95+
delegate_to: 127.0.0.1

tasks/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
include: install_podman.yml
5353
when: nomad_podman_enable | bool
5454

55+
- name: Install CNI plugin
56+
include: cni.yml
57+
when: nomad_cni_enable | bool
58+
5559
- name: Create config directory
5660
file:
5761
dest: "{{ nomad_config_dir }}"
@@ -77,6 +81,10 @@
7781
- nomad_encrypt_enable | bool
7882
- nomad_encrypt is not defined
7983

84+
- name: Create TLS configuration
85+
include_tasks: tls.yml
86+
when: nomad_tls_enable | bool
87+
8088
- name: Server configuration
8189
template:
8290
src: server.hcl.j2

tasks/tls.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
# File: tls.yml - TLS tasks for Nomad
3+
4+
- block:
5+
- name: Create SSL directory
6+
file:
7+
dest: "{{ nomad_tls_dir }}"
8+
state: directory
9+
owner: "{{ nomad_user }}"
10+
group: "{{ nomad_group }}"
11+
mode: 0755
12+
13+
- name: Copy CA certificate
14+
copy:
15+
remote_src: "{{ nomad_tls_files_remote_src }}"
16+
src: "{{ nomad_ca_file }}"
17+
dest: "{{ nomad_tls_dir }}/{{ nomad_ca_file | basename }}"
18+
owner: "{{ nomad_user }}"
19+
group: "{{ nomad_group }}"
20+
mode: 0644
21+
notify: restart nomad
22+
23+
- name: Copy certificate
24+
copy:
25+
remote_src: "{{ nomad_tls_files_remote_src }}"
26+
src: "{{ nomad_cert_file }}"
27+
dest: "{{ nomad_tls_dir }}/{{ nomad_cert_file | basename }}"
28+
owner: "{{ nomad_user }}"
29+
group: "{{ nomad_group }}"
30+
mode: 0644
31+
notify: restart nomad
32+
33+
- name: Copy key
34+
copy:
35+
remote_src: "{{ nomad_tls_files_remote_src }}"
36+
src: "{{ nomad_key_file }}"
37+
dest: "{{ nomad_tls_dir }}/{{ nomad_key_file | basename }}"
38+
owner: "{{ nomad_user }}"
39+
group: "{{ nomad_group }}"
40+
mode: 0600
41+
notify: restart nomad
42+
43+
when: nomad_tls_copy_keys | bool

templates/base.hcl.j2

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ ports {
2222
consul {
2323
# The address to the Consul agent.
2424
address = "{{ nomad_consul_address }}"
25+
ssl = {{ nomad_consul_ssl | bool | lower }}
26+
ca_file = "{{ nomad_consul_ca_file }}"
27+
cert_file = "{{ nomad_consul_cert_file }}"
28+
key_file = "{{ nomad_consul_key_file }}"
2529
token = "{{ nomad_consul_token }}"
2630
# The service name to register the server and client with Consul.
2731
server_service_name = "{{ nomad_consul_servers_service_name }}"
@@ -49,9 +53,9 @@ leave_on_interrupt = {{ nomad_leave_on_interrupt | bool | lower }}
4953
tls {
5054
http = true
5155
rpc = true
52-
ca_file = "{{ nomad_ca_file }}"
53-
cert_file = "{{ nomad_cert_file }}"
54-
key_file = "{{ nomad_key_file }}"
56+
ca_file = "{{ nomad_tls_dir }}/{{ nomad_ca_file | basename }}"
57+
cert_file = "{{ nomad_tls_dir }}/{{ nomad_cert_file | basename }}"
58+
key_file = "{{ nomad_tls_dir }}/{{ nomad_key_file | basename }}"
5559
rpc_upgrade_mode = {{ nomad_rpc_upgrade_mode | bool | lower }}
5660
verify_server_hostname = "{{ nomad_verify_server_hostname | bool | lower }}"
5761
verify_https_client = "{{ nomad_verify_https_client | bool | lower }}"

templates/client.hcl.j2

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ client {
3838
}
3939
{% endfor %}
4040

41+
{% for nomad_host_network in nomad_host_networks %}
42+
host_network "{{ nomad_host_network['name'] }}" {
43+
{% if 'cidr' in nomad_host_network %}
44+
cidr = "{{ nomad_host_network['cidr'] | default}}"
45+
{% else %}
46+
interface = "{{ nomad_host_network['interface'] }}"
47+
{% endif %}
48+
reserved_ports = "{{ nomad_host_network['reserved_ports'] }}"
49+
}
50+
{% endfor %}
51+
4152
{% if nomad_chroot_env != False -%}
4253
chroot_env = {
4354
{% for key, value in nomad_chroot_env.items() %}

0 commit comments

Comments
 (0)