Skip to content

Commit 0f86b8b

Browse files
authored
Merge pull request #71 from wiseflat/dev/mgarcia/nomad-eligibility
Fix: Update nomad eligibility strategy
2 parents bcd82c7 + 3c5a011 commit 0f86b8b

5 files changed

Lines changed: 33 additions & 9 deletions

File tree

ansible/playbooks/paas/roles/nomad/tasks/04_tls_certs.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
notify: Nomad_restart
6161

6262
- name: Nomad | Copy certificate on client nodes
63-
when: nomad_node_role in ['client', 'both']
63+
when: nomad_node_role in ['client']
6464
block:
6565
- name: "Nomad | Check if TLS cert exists for Client"
6666
ansible.builtin.stat:
@@ -88,7 +88,9 @@
8888
certificate_client_privatekey: "{{ nomad_tls_privatekey_client }}"
8989
certificate_common_name: "{{ nomad_tls_common_name_client }}"
9090
certificate_subject_alt_name: "{{ nomad_tls_subject_alt_name_client }}"
91-
# when: nomad_mode == 'cluster'
91+
run_once: true
92+
when: not cert_tls_client_present.stat.exists or (cert_tls_client_present.stat.exists and not tls_check_client.valid_at.delay)
93+
9294

9395
- name: "Nomad | Copy certificates on client nodes"
9496
ansible.builtin.copy:

ansible/playbooks/paas/roles/nomad/tasks/06_configuration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
- name: Block
33
block:
4-
- name: "Nomad Install | Read Gossip Encryption Key from PasswordStore"
4+
- name: "Nomad Install | Read Gossip Encryption Key"
55
ansible.builtin.set_fact:
66
nomad_encrypt_key: "{{ lookup('simple-stack-ui', type='secret', key=inventory_hostname, subkey='nomad_encrypt_key', missing='error') }}"
77
rescue:
@@ -11,7 +11,7 @@
1111
changed_when: nomad_encrypt_key_out.rc != 0
1212
run_once: true
1313

14-
- name: "Nomad Install | Set Gossip Encryption Key and insert in PasswordStore"
14+
- name: "Nomad Install | Save Gossip Encryption Key"
1515
ansible.builtin.set_fact:
1616
nomad_encrypt_key: "{{ lookup('simple-stack-ui', type='secret', key=inventory_hostname, subkey='nomad_encrypt_key', missing='create', userpass=nomad_encrypt_key_out.stdout) }}"
1717

ansible/playbooks/paas/roles/nomad/tasks/07_autoeligibility.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
- 200
105105
register: nomad_new_token_name
106106

107-
- name: "Nomad Install | Set Nomad Autoeligibility token and insert in PasswordStore"
107+
- name: "Nomad Install | Save Nomad Autoeligibility token"
108108
ansible.builtin.set_fact:
109109
nomad_autoeligibility_token: "{{ lookup('simple-stack-ui', type='secret', key=inventory_hostname, subkey='nomad_autoeligibility_token', missing='create', userpass=nomad_new_token_name.json.SecretID) }}"
110110

ansible/playbooks/paas/roles/nomad/tasks/08_systemd_tuning.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
66
owner: "root"
77
group: "root"
88

9+
- name: "Nomad Policy | Get node id"
10+
ansible.builtin.uri:
11+
url: "{{ nomad_http_scheme }}://{{ nomad_http_ip }}:{{ nomad_http_port }}/v1/nodes"
12+
ca_path: "{{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_ca_pubkey }}"
13+
client_cert: "{{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_cert_server }}"
14+
client_key: "{{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_privatekey_server }}"
15+
method: GET
16+
headers:
17+
X-Nomad-Token: "{{ lookup('simple-stack-ui', type='secret', key=nomad_primary_master_node | default(inventory_hostname), subkey='nomad_management_token', missing='error') }}"
18+
status_code:
19+
- 200
20+
- 404
21+
return_content: true
22+
delegate_to: "{{ nomad_primary_master_node | default(inventory_hostname) }}"
23+
register: nomad_node_id
24+
25+
- name: Nomad Policy | Set Node id as a fact
26+
ansible.builtin.set_fact:
27+
node_id: "{{ item.ID }}"
28+
loop: "{{ nomad_node_id.json }}"
29+
when: item.Name == inventory_hostname
30+
931
- name: Nomad SystemD tuning | Template for systemd override
1032
ansible.builtin.template:
1133
src: "override.conf.j2"

ansible/playbooks/paas/roles/nomad/templates/override.conf.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ After=docker.service
33

44
[Service]
55
ExecReload=/bin/kill --signal HUP $MAINPID
6-
{% if nomad_mode == 'single' %}
7-
ExecStartPost=/usr/bin/nomad node eligibility -enable -self -address={{ nomad_http_scheme }}://{{ nomad_http_ip }}:{{ nomad_http_port }} -ca-cert={{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_ca_pubkey }} -client-cert={{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_cert_server }} -client-key={{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_privatekey_server }} -token={{ nomad_autoeligibility_token }}
8-
ExecStop=/usr/bin/nomad node drain -enable -self -address={{ nomad_http_scheme }}://{{ nomad_http_ip }}:{{ nomad_http_port }} -ca-cert={{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_ca_pubkey }} -client-cert={{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_cert_server }} -client-key={{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_privatekey_server }} -token={{ nomad_autoeligibility_token }}
9-
{% endif %}
6+
{% if nomad_node_role in ['both', 'client'] %}
7+
ExecStartPost=/usr/bin/nomad node eligibility -enable -address={{ nomad_http_scheme }}://{{ hostvars[nomad_primary_master_node | default(inventory_hostname)]['ansible_' + nomad_iface].ipv4.address | default('127.0.0.1') }}:{{ nomad_http_port }} -ca-cert={{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_ca_pubkey }} -client-cert={{ nomad_tls_host_certificate_dir }}/{{ inventory_hostname }}-dc1-client-nomad.pem -client-key={{ nomad_tls_host_certificate_dir }}/{{ inventory_hostname }}-dc1-client-nomad.key -token={{ lookup('simple-stack-ui', type='secret', key=nomad_primary_master_node | default(inventory_hostname), subkey='nomad_management_token', missing='error') }} {{ node_id }}
8+
ExecStop=/usr/bin/nomad node drain -enable -address={{ nomad_http_scheme }}://{{ hostvars[nomad_primary_master_node | default(inventory_hostname)]['ansible_' + nomad_iface].ipv4.address | default('127.0.0.1') }}:{{ nomad_http_port }} -ca-cert={{ nomad_tls_host_certificate_dir }}/{{ nomad_tls_ca_pubkey }} -client-cert={{ nomad_tls_host_certificate_dir }}/{{ inventory_hostname }}-dc1-client-nomad.pem -client-key={{ nomad_tls_host_certificate_dir }}/{{ inventory_hostname }}-dc1-client-nomad.key -token={{ lookup('simple-stack-ui', type='secret', key=nomad_primary_master_node | default(inventory_hostname), subkey='nomad_management_token', missing='error') }} {{ node_id }}
9+
{% endif %}

0 commit comments

Comments
 (0)