mirror of
https://git.lapiole.org/dani/ansible-roles.git
synced 2025-07-27 08:15:54 +02:00
Update to 2022-09-06 18:00
This commit is contained in:
@@ -57,7 +57,7 @@ nomad_base_conf:
|
||||
|
||||
|
||||
# TLS Settings
|
||||
# See the nomad_vault_tls configuration if you want to integrate with vault to obtain and renew the certificates
|
||||
# See the nomad_vault_secrets configuration if you want to integrate with vault to obtain and renew the certificates
|
||||
tls:
|
||||
http: False
|
||||
rpc: False
|
||||
@@ -228,23 +228,23 @@ nomad_host_services: {}
|
||||
nomad_services: "{{ nomad_base_services | combine(nomad_extra_services, recursive=True) | combine(nomad_host_services, recursive=True) }}"
|
||||
|
||||
# When using vault to setup TLS for Nomad
|
||||
nomad_base_vault_tls:
|
||||
enabled: False
|
||||
address: "{{ nomad_conf.vault.address | default(omit) }}"
|
||||
nomad_base_vault_secrets:
|
||||
vault_address: "{{ nomad_conf.vault.address | default(omit) }}"
|
||||
# Token to use to issue certificates
|
||||
# token: XXXXXXXXX
|
||||
pki:
|
||||
enabled: False
|
||||
# The path of the PKI secret where cert will be issued
|
||||
path: /pki/nomad
|
||||
role: nomad-{{ nomad_conf.server.enabled | ternary('server', 'client') }}
|
||||
ttl: 24h
|
||||
# ttl: 6h # if not set, will use the default ttl of the role
|
||||
consul_pki:
|
||||
enabled: False
|
||||
path: /pki/consul
|
||||
role: nomad-client # Only nomad clients will use the gRPC endpoint and requires a client cert for consul
|
||||
ttl: 24h
|
||||
root_pki:
|
||||
path: /pki/root # This is used to fetch the top level root CA, as envoy can't validate the chain unless it has it complete up to the auto-signed root
|
||||
root_path: /pki/root # This is used to fetch the top level root CA, as envoy can't validate the chain unless it has it complete up to the auto-signed root
|
||||
role: nomad-client # Only nomad clients will use this
|
||||
# ttl: 6h # if not set, will use the default ttl of the role
|
||||
|
||||
nomad_extra_vault_tls: {}
|
||||
nomad_host_vault_tls: {}
|
||||
nomad_vault_tls: "{{ nomad_base_vault_tls | combine(nomad_extra_vault_tls, recursive=True) | combine(nomad_host_vault_tls, recursive=True) }}"
|
||||
nomad_extra_vault_secrets: {}
|
||||
nomad_host_vault_secrets: {}
|
||||
nomad_vault_secrets: "{{ nomad_base_vault_secrets | combine(nomad_extra_vault_secrets, recursive=True) | combine(nomad_host_vault_secrets, recursive=True) }}"
|
||||
|
@@ -113,38 +113,34 @@
|
||||
loop: "{{ nomad_backup_configs.stdout_lines }}"
|
||||
tags: nomad
|
||||
|
||||
- when: nomad_vault_tls.enabled
|
||||
block:
|
||||
|
||||
- name: Deploy consul-template config
|
||||
template: src=consul-template.hcl.j2 dest={{ nomad_root_dir }}/consul-template/consul-template.hcl
|
||||
notify: restart consul-template-nomad
|
||||
|
||||
- name: Deploy consul-template agent cert template
|
||||
template: src=agent_cert.tpl.j2 dest={{ nomad_root_dir }}/consul-template/{{ item.where }} owner=root group=root
|
||||
loop:
|
||||
- what: certificate
|
||||
where: agent.crt.tpl
|
||||
- what: private_key
|
||||
where: agent.key.tpl
|
||||
- what: issuing_ca
|
||||
where: ca.crt.tpl
|
||||
notify: restart consul-template-nomad
|
||||
|
||||
- name: Deploy consul-template config
|
||||
template: src=consul-template.hcl.j2 dest={{ nomad_root_dir }}/consul-template/consul-template.hcl mode=600 owner=root group=root
|
||||
notify: restart consul-template-nomad
|
||||
when: nomad_vault_secrets.pki.enabled or nomad_vault_secrets.tokens.enabled
|
||||
tags: nomad
|
||||
|
||||
- when: nomad_vault_tls.enabled and nomad_conf.server.enabled
|
||||
block:
|
||||
|
||||
- name: Deploy consul-template cli cert template
|
||||
template: src=cli_cert.tpl.j2 dest={{ nomad_root_dir }}/consul-template/{{ item.where }} owner=root group=root
|
||||
loop:
|
||||
- what: certificate
|
||||
where: cli.crt.tpl
|
||||
- what: private_key
|
||||
where: cli.key.tpl
|
||||
notify: restart consul-template-nomad
|
||||
- name: Deploy consul-template agent cert template
|
||||
template: src=agent_cert.tpl.j2 dest={{ nomad_root_dir }}/consul-template/{{ item.where }} owner=root group=root
|
||||
loop:
|
||||
- what: certificate
|
||||
where: agent.crt.tpl
|
||||
- what: private_key
|
||||
where: agent.key.tpl
|
||||
- what: issuing_ca
|
||||
where: ca.crt.tpl
|
||||
notify: restart consul-template-nomad
|
||||
when: nomad_vault_secrets.pki.enabled
|
||||
tags: nomad
|
||||
|
||||
- name: Deploy consul-template cli cert template
|
||||
template: src=cli_cert.tpl.j2 dest={{ nomad_root_dir }}/consul-template/{{ item.where }} owner=root group=root
|
||||
loop:
|
||||
- what: certificate
|
||||
where: cli.crt.tpl
|
||||
- what: private_key
|
||||
where: cli.key.tpl
|
||||
notify: restart consul-template-nomad
|
||||
when: nomad_vault_secrets.pki.enabled and nomad_conf.server.enabled
|
||||
tags: nomad
|
||||
|
||||
- name: Set ACL on the TLS dir
|
||||
@@ -172,6 +168,6 @@
|
||||
- what: issuing_ca
|
||||
where: consul_ca.crt.tpl
|
||||
notify: restart consul-template-nomad
|
||||
when: nomad_conf.client.enabled and nomad_conf.consul.ssl
|
||||
when: nomad_vault_secrets.consul_pki.enabled and nomad_conf.client.enabled and nomad_conf.consul.ssl
|
||||
tags: nomad
|
||||
|
||||
|
@@ -114,6 +114,7 @@
|
||||
template: src=consul-template-nomad.service.j2 dest=/etc/systemd/system/consul-template-nomad.service
|
||||
register: nomad_consul_tpl_unit
|
||||
notify: restart consul-template-nomad
|
||||
when: nomad_vault_secrets.pki.enabled or nomad_vault_secrets.consul_pki.enabled
|
||||
tags: nomad
|
||||
|
||||
- name: Reload systemd
|
||||
|
@@ -6,5 +6,8 @@
|
||||
tags: nomad
|
||||
|
||||
- name: Handle consul-template-nomad service
|
||||
service: name=consul-template-nomad state={{ nomad_vault_tls.enabled | ternary('started', 'stopped') }} enabled={{ nomad_vault_tls.enabled | ternary(True, False) }}
|
||||
service:
|
||||
name: consul-template-nomad
|
||||
state: "{{ (nomad_vault_secrets.pki.enabled or nomad_vault_secrets.consul_pki.enabled or nomad_vault_secrets.tokens.enabled) | ternary('started', 'stopped') }}"
|
||||
enabled: "{{ (nomad_vault_secrets.pki.enabled or nomad_vault_secrets.consul_pki.enabled or nomad_vault_secrets.tokens.enabled) | ternary(True, False) }}"
|
||||
tags: nomad
|
||||
|
@@ -1,8 +1,8 @@
|
||||
[[ with secret "{{ nomad_vault_tls.pki.path }}/issue/{{ nomad_vault_tls.pki.role }}" "common_name={{ (nomad_conf.server.enabled) | ternary('server', 'client') }}-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ nomad_conf.region | default('global') }}.nomad" "ttl={{ nomad_vault_tls.pki.ttl }}" "alt_names=localhost,{{ (nomad_conf.server.enabled) | ternary('server', 'client') }}.{{ nomad_conf.region | default('global') }}.nomad{% if nomad_conf.server.enabled and nomad_conf.client.enabled %},client.{{ nomad_conf.region | default('global') }}.nomad{% endif %}{% if consul_conf is defined %},nomad{{ nomad_conf.server.enabled | ternary('', '-client') }}.service.{{ consul_conf.domain | default('consul') }}{% endif %}" ]]
|
||||
[[ with secret "{{ nomad_vault_secrets.pki.path }}/issue/{{ nomad_vault_secrets.pki.role }}" "common_name={{ (nomad_conf.server.enabled) | ternary('server', 'client') }}-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ nomad_conf.region | default('global') }}.nomad" "alt_names=localhost,{{ (nomad_conf.server.enabled) | ternary('server', 'client') }}.{{ nomad_conf.region | default('global') }}.nomad{% if nomad_conf.server.enabled and nomad_conf.client.enabled %},client.{{ nomad_conf.region | default('global') }}.nomad{% endif %}{% if consul_conf is defined %},nomad{{ nomad_conf.server.enabled | ternary('', '-client') }}.service.{{ consul_conf.domain | default('consul') }}{% endif %}"{% if nomad_vault_secrets.pki.ttl is defined %} "ttl={{ nomad_vault_secrets.pki.ttl }}"{% endif %} ]]
|
||||
[[ .Data.{{ item.what }} ]]
|
||||
[[ end ]]
|
||||
{% if item.what == 'certificate' %}
|
||||
[[ with secret "{{ nomad_vault_tls.pki.path }}/cert/ca" ]]
|
||||
[[ with secret "{{ nomad_vault_secrets.pki.path }}/cert/ca" ]]
|
||||
[[ .Data.certificate ]]
|
||||
[[ end ]]
|
||||
{% endif %}
|
||||
|
@@ -1,3 +1,3 @@
|
||||
[[ with secret "{{ nomad_vault_tls.pki.path }}/issue/{{ nomad_vault_tls.pki.role }}" "ttl={{ nomad_vault_tls.pki.ttl }}" "common_name=cli-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ nomad_conf.region | default('global') }}.nomad" ]]
|
||||
[[ with secret "{{ nomad_vault_secrets.pki.path }}/issue/{{ nomad_vault_secrets.pki.role }}" "common_name=cli-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ nomad_conf.region | default('global') }}.nomad" ]]
|
||||
[[ .Data.{{ item.what }} ]]
|
||||
[[ end ]]
|
||||
|
@@ -3,11 +3,13 @@ Description="HashiCorp consul-template"
|
||||
Documentation=https://github.com/hashicorp/consul-template
|
||||
Requires=network-online.target
|
||||
After=network-online.target
|
||||
Before=nomad.service
|
||||
ConditionFileNotEmpty={{ nomad_root_dir }}/consul-template/consul-template.hcl
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/consul-template -config={{ nomad_root_dir }}/consul-template/consul-template.hcl
|
||||
SuccessExitStatus=12
|
||||
ExecReload=/bin/kill --signal HUP $MAINPID
|
||||
KillSignal=SIGINT
|
||||
Restart=on-failure
|
||||
|
@@ -1,9 +1,12 @@
|
||||
vault {
|
||||
address = "{{ nomad_vault_tls.address }}"
|
||||
token = "{{ nomad_vault_tls.token }}"
|
||||
address = "{{ nomad_vault_secrets.vault_address }}"
|
||||
token = "{{ nomad_vault_secrets.vault_token }}"
|
||||
unwrap_token = false
|
||||
}
|
||||
|
||||
# Sleep 10 sec before sending nomad service a reload to prevent it from crashing as
|
||||
# Nomad doesn't support getting a reload while it's still initializing
|
||||
{% if nomad_vault_secrets.pki.enabled %}
|
||||
template {
|
||||
source = "{{ nomad_root_dir }}/consul-template/agent.crt.tpl"
|
||||
left_delimiter = "[["
|
||||
@@ -11,7 +14,7 @@ template {
|
||||
destination = "{{ nomad_conf.tls.cert_file }}"
|
||||
perms = 0644
|
||||
exec {
|
||||
command = "systemctl reload nomad"
|
||||
command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +25,7 @@ template {
|
||||
destination = "{{ nomad_conf.tls.key_file }}"
|
||||
perms = 0640
|
||||
exec {
|
||||
command = ["sh", "-c", "chgrp {{ nomad_user }} {{ nomad_conf.tls.key_file }} && systemctl reload nomad"]
|
||||
command = ["sh", "-c", "chgrp {{ nomad_user }} {{ nomad_conf.tls.key_file }} && sleep 10 && systemctl reload nomad || true"]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +36,7 @@ template {
|
||||
destination = "{{ nomad_conf.tls.ca_file }}"
|
||||
perms = 0644
|
||||
exec {
|
||||
command = "systemctl reload nomad"
|
||||
command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,13 +56,18 @@ template {
|
||||
perms = 0640
|
||||
}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if nomad_conf.client.enabled and nomad_conf.consul.ssl %}
|
||||
|
||||
{% if nomad_vault_secrets.consul_pki.enabled and nomad_conf.client.enabled and nomad_conf.consul.ssl %}
|
||||
template {
|
||||
source = "{{ nomad_root_dir }}/consul-template/consul.crt.tpl"
|
||||
left_delimiter = "[["
|
||||
right_delimiter = "]]"
|
||||
destination = "{{ nomad_conf.consul.cert_file }}"
|
||||
exec {
|
||||
command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
|
||||
}
|
||||
}
|
||||
|
||||
template {
|
||||
@@ -68,6 +76,9 @@ template {
|
||||
right_delimiter = "]]"
|
||||
destination = "{{ nomad_conf.consul.key_file }}"
|
||||
perms = 0640
|
||||
exec {
|
||||
command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
|
||||
}
|
||||
}
|
||||
|
||||
template {
|
||||
@@ -77,8 +88,8 @@ template {
|
||||
destination = "{{ nomad_conf.consul.ca_file }}"
|
||||
perms = 0644
|
||||
exec {
|
||||
command = "systemctl reload nomad"
|
||||
command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
|
||||
}
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
[[ with secret "{{ nomad_vault_tls.consul_pki.path }}/issue/{{ nomad_vault_tls.consul_pki.role }}" "common_name={{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ (consul_conf is defined and consul_conf.domain is defined) | ternary(consul_conf.domain, 'consul') }}" "ttl={{ nomad_vault_tls.consul_pki.ttl }}" ]]
|
||||
[[ with secret "{{ nomad_vault_secrets.consul_pki.path }}/issue/{{ nomad_vault_secrets.consul_pki.role }}" "common_name={{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ (consul_conf is defined and consul_conf.domain is defined) | ternary(consul_conf.domain, 'consul') }}"{% if nomad_vault_secrets.consul_pki.ttl is defined %} "ttl={{ nomad_vault_secrets.consul_pki.ttl }}"{% endif %} ]]
|
||||
[[ .Data.{{ item.what }} ]]
|
||||
[[ end ]]
|
||||
{% if item.what == 'issuing_ca' %}
|
||||
[[ with secret "{{ nomad_vault_tls.root_pki.path }}/cert/ca" ]]
|
||||
[[ with secret "{{ nomad_vault_secrets.consul_pki.root_path }}/cert/ca" ]]
|
||||
[[ .Data.certificate ]]
|
||||
[[ end ]]
|
||||
{% endif %}
|
||||
|
@@ -210,11 +210,20 @@ vault {
|
||||
{{ key }} = {{ nomad_conf.vault[key] | ternary('true', 'false') }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if nomad_conf.server.enabled %}
|
||||
{% for key in ['address', 'create_from_role', 'task_token_ttl', 'ca_file', 'ca_path', 'cert_file', 'key_file', 'namespace', 'tls_server_name', 'token'] %}
|
||||
{% if nomad_conf.vault[key] is defined %}
|
||||
{{ key }} = "{{ nomad_conf.vault[key] }}"
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% elif nomad_conf.client.enabled and not nomad_conf.server.enabled %}
|
||||
{% for key in ['address', 'ca_file', 'ca_path', 'cert_file', 'key_file', 'namespace', 'tls_server_name'] %}
|
||||
{% if nomad_conf.vault[key] is defined %}
|
||||
{{ key }} = "{{ nomad_conf.vault[key] }}"
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
tls {
|
||||
|
@@ -6,7 +6,7 @@ set -eo pipefail
|
||||
NOMAD_ADDR=https://localhost:{{ nomad_services.http.port }} \
|
||||
NOMAD_CACERT={{ nomad_conf.tls.ca_file }} \
|
||||
{% endif %}
|
||||
{% if nomad_vault_tls.enabled %}
|
||||
{% if nomad_vault_secrets.pki.enabled %}
|
||||
NOMAD_CLIENT_CERT={{ nomad_root_dir }}/tls/cli.crt \
|
||||
NOMAD_CLIENT_KEY={{ nomad_root_dir }}/tls/cli.key \
|
||||
{% endif %}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
{% if nomad_conf.tls.http and nomad_conf.server.enabled %}
|
||||
export NOMAD_ADDR=https://localhost:{{ nomad_services.http.port }}
|
||||
export NOMAD_CACERT={{ nomad_conf.tls.ca_file }}
|
||||
{% if nomad_vault_tls.enabled %}
|
||||
{% if nomad_vault_secrets.pki.enabled %}
|
||||
export NOMAD_CLIENT_CERT={{ nomad_root_dir }}/tls/cli.crt
|
||||
export NOMAD_CLIENT_KEY={{ nomad_root_dir }}/tls/cli.key
|
||||
export NOMAD_TLS_SERVER_NAME=server.{{ nomad_conf.region | default('global') }}.nomad
|
||||
|
Reference in New Issue
Block a user