mirror of
				https://git.lapiole.org/dani/ansible-roles.git
				synced 2025-11-03 12:21:28 +01:00 
			
		
		
		
	Update to 2022-09-13 17:00
This commit is contained in:
		@@ -100,26 +100,14 @@
 | 
				
			|||||||
  when: consul_vault_secrets.pki.enabled or consul_vault_secrets.tokens.enabled
 | 
					  when: consul_vault_secrets.pki.enabled or consul_vault_secrets.tokens.enabled
 | 
				
			||||||
  tags: consul
 | 
					  tags: consul
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Deploy consul-template agent cert template
 | 
					- name: Deploy agent bundle template
 | 
				
			||||||
  template: src=agent_cert.tpl.j2 dest={{ consul_root_dir }}/consul-template/{{ item.where }} owner=root group=root
 | 
					  template: src=agent_bundle.pem.tpl.j2 dest={{ consul_root_dir }}/consul-template/agent_bundle.pem.tpl 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-consul
 | 
					  notify: restart consul-template-consul
 | 
				
			||||||
  when: consul_vault_secrets.pki.enabled
 | 
					  when: consul_vault_secrets.pki.enabled
 | 
				
			||||||
  tags: consul
 | 
					  tags: consul
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Deploy consul-template cli cert template
 | 
					- name: Deploy consul-template cli bundle template
 | 
				
			||||||
  template: src=cli_cert.tpl.j2 dest={{ consul_root_dir }}/consul-template/{{ item.where }} owner=root group=root
 | 
					  template: src=cli_bundle.pem.tpl.j2 dest={{ consul_root_dir }}/consul-template/cli_bundle.pem.tpl owner=root group=root
 | 
				
			||||||
  loop:
 | 
					 | 
				
			||||||
    - what: certificate
 | 
					 | 
				
			||||||
      where: cli.crt.tpl
 | 
					 | 
				
			||||||
    - what: private_key
 | 
					 | 
				
			||||||
      where: cli.key.tpl
 | 
					 | 
				
			||||||
  notify: restart consul-template-consul
 | 
					  notify: restart consul-template-consul
 | 
				
			||||||
  when: consul_vault_secrets.pki.enabled and consul_conf.server
 | 
					  when: consul_vault_secrets.pki.enabled and consul_conf.server
 | 
				
			||||||
  tags: consul
 | 
					  tags: consul
 | 
				
			||||||
@@ -132,10 +120,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
- name: Set ACL on the TLS dir
 | 
					- name: Set ACL on the TLS dir
 | 
				
			||||||
  shell: |
 | 
					  shell: |
 | 
				
			||||||
    setfacl -R -b -x {{ consul_root_dir }}/tls
 | 
					    setfacl -R -b -k {{ consul_root_dir }}/tls
 | 
				
			||||||
    {% if consul_admin_groups | length > 0 %}
 | 
					    {% if consul_admin_groups | length > 0 %}
 | 
				
			||||||
    setfacl -R -m {% for group in consul_admin_groups %}g:{{ group }}:rX{{ ',' if not loop.last }}{% endfor %} {{ consul_root_dir }}/tls
 | 
					    setfacl -m {% for group in consul_admin_groups %}g:{{ group }}:rx{{ ',' if not loop.last }}{% endfor %} {{ consul_root_dir }}/tls
 | 
				
			||||||
    setfacl -R -m {% for group in consul_admin_groups %}d:g:{{ group }}:rX{{ ',' if not loop.last }}{% endfor %} {{ consul_root_dir }}/tls
 | 
					    setfacl -m {% for group in consul_admin_groups %}d:g:{{ group }}:r{{ ',' if not loop.last }}{% endfor %} {{ consul_root_dir }}/tls
 | 
				
			||||||
 | 
					    setfacl -m {% for group in consul_admin_groups %}g:{{ group }}:r{{ ',' if not loop.last }}{% endfor %} {{ consul_root_dir }}/tls/*
 | 
				
			||||||
    {% endif %}
 | 
					    {% endif %}
 | 
				
			||||||
  changed_when: False
 | 
					  changed_when: False
 | 
				
			||||||
  failed_when: False # Do not fail if eg, the FS doesn't support ACL
 | 
					  failed_when: False # Do not fail if eg, the FS doesn't support ACL
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										18
									
								
								roles/consul/templates/agent_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								roles/consul/templates/agent_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					{% if consul_conf.server %}
 | 
				
			||||||
 | 
					[[ with pkiCert "{{ consul_vault_secrets.pki.path }}/issue/{{ consul_vault_secrets.pki.role }}" "common_name=server-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ consul_conf.datacenter | default('dc1') }}.{{ consul_conf.domain | default('consul') }}" "alt_names=localhost,consul.service.{{ consul_conf.domain | default('consul') }},server.{{ consul_conf.datacenter | default('dc1') }}.{{ consul_conf.domain | default('consul') }}" ]]
 | 
				
			||||||
 | 
					[[ .CA ]]
 | 
				
			||||||
 | 
					[[ .Cert ]]
 | 
				
			||||||
 | 
					[[ .Key ]]
 | 
				
			||||||
 | 
					[[ .CA | writeToFile "{{ consul_conf.tls.defaults.ca_file }}" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ .Cert | writeToFile "{{ consul_conf.tls.defaults.cert_file }}" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ .Key | writeToFile "{{ consul_conf.tls.defaults.key_file }}" "root" "{{ consul_user }}" "0640" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
 | 
					[[ with secret "{{ consul_vault_secrets.pki.path }}/cert/ca" ]]
 | 
				
			||||||
 | 
					[[ .Data.certificate | writeToFile "{{ consul_conf.tls.defaults.cert_file }}" "root" "root" "0644" "append,newline" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
 | 
					{% else %}
 | 
				
			||||||
 | 
					[[ with secret "{{ consul_vault_secrets.pki.path }}/cert/ca" ]]
 | 
				
			||||||
 | 
					[[ .Data.certificate | writeToFile "{{ consul_conf.tls.defaults.ca_file }}" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
 | 
					{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,14 +0,0 @@
 | 
				
			|||||||
{% if consul_conf.server %}
 | 
					 | 
				
			||||||
[[ with secret "{{ consul_vault_secrets.pki.path }}/issue/{{ consul_vault_secrets.pki.role }}" "common_name=server-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ consul_conf.datacenter | default('dc1') }}.{{ consul_conf.domain | default('consul') }}" "alt_names=localhost,consul.service.{{ consul_conf.domain | default('consul') }},server.{{ consul_conf.datacenter | default('dc1') }}.{{ consul_conf.domain | default('consul') }}" ]]
 | 
					 | 
				
			||||||
[[ .Data.{{ item.what }} ]]
 | 
					 | 
				
			||||||
[[ end ]]
 | 
					 | 
				
			||||||
{% if item.what == 'certificate' %}
 | 
					 | 
				
			||||||
[[ with secret "{{ consul_vault_secrets.pki.path }}/cert/ca" ]]
 | 
					 | 
				
			||||||
[[ .Data.certificate ]]
 | 
					 | 
				
			||||||
[[ end ]]
 | 
					 | 
				
			||||||
{% endif %}
 | 
					 | 
				
			||||||
{% else %}
 | 
					 | 
				
			||||||
[[ with secret "{{ consul_vault_secrets.pki.path }}/cert/ca" ]]
 | 
					 | 
				
			||||||
[[ .Data.certificate ]]
 | 
					 | 
				
			||||||
[[ end ]]
 | 
					 | 
				
			||||||
{% endif %}
 | 
					 | 
				
			||||||
							
								
								
									
										7
									
								
								roles/consul/templates/cli_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								roles/consul/templates/cli_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					[[ with pkiCert "{{ consul_vault_secrets.pki.path }}/issue/{{ consul_vault_secrets.pki.role }}" "common_name=cli-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ consul_conf.datacenter | default('dc1') }}.{{ consul_conf.domain | default('consul') }}" ]]
 | 
				
			||||||
 | 
					[[ .CA ]]
 | 
				
			||||||
 | 
					[[ .Cert ]]
 | 
				
			||||||
 | 
					[[ .Key ]]
 | 
				
			||||||
 | 
					[[ .Cert | writeToFile "{{ consul_root_dir }}/tls/cli.crt" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ .Key | writeToFile "{{ consul_root_dir }}/tls/cli.key" "root" "root" "0640" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
@@ -1,3 +0,0 @@
 | 
				
			|||||||
[[ with secret "{{ consul_vault_secrets.pki.path }}/issue/{{ consul_vault_secrets.pki.role }}" "common_name=cli-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ consul_conf.datacenter | default('dc1') }}.{{ consul_conf.domain | default('consul') }}" ]]
 | 
					 | 
				
			||||||
[[ .Data.{{ item.what }} ]]
 | 
					 | 
				
			||||||
[[ end ]]
 | 
					 | 
				
			||||||
@@ -5,55 +5,27 @@ vault {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template {
 | 
					template {
 | 
				
			||||||
  source          = "{{ consul_root_dir }}/consul-template/ca.crt.tpl"
 | 
					  source          = "{{ consul_root_dir }}/consul-template/agent_bundle.pem.tpl"
 | 
				
			||||||
  left_delimiter  = "[["
 | 
					  left_delimiter  = "[["
 | 
				
			||||||
  right_delimiter = "]]"
 | 
					  right_delimiter = "]]"
 | 
				
			||||||
  destination     = "{{ consul_conf.tls.defaults.ca_file }}"
 | 
					  destination     = "{{ consul_root_dir }}/tls/agent_bundle.pem"
 | 
				
			||||||
  perms           = 0644
 | 
					  perms           = 0640
 | 
				
			||||||
  exec {
 | 
					  exec {
 | 
				
			||||||
    command = "sh -c 'systemctl reload consul || true'"
 | 
					    command = "sh -c 'systemctl reload consul || true'"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if consul_vault_secrets.pki.enabled %}
 | 
					 | 
				
			||||||
{% if consul_conf.server %}
 | 
					{% if consul_conf.server %}
 | 
				
			||||||
template {
 | 
					template {
 | 
				
			||||||
  source          = "{{ consul_root_dir }}/consul-template/agent.crt.tpl"
 | 
					  source          = "{{ consul_root_dir }}/consul-template/cli_bundle.pem.tpl"
 | 
				
			||||||
  left_delimiter  = "[["
 | 
					  left_delimiter  = "[["
 | 
				
			||||||
  right_delimiter = "]]"
 | 
					  right_delimiter = "]]"
 | 
				
			||||||
  destination     = "{{ consul_conf.tls.defaults.cert_file }}"
 | 
					  destination     = "{{ consul_root_dir }}/tls/cli_bundle.pem"
 | 
				
			||||||
  perms           = 0644
 | 
					  perms           = 0640
 | 
				
			||||||
  exec {
 | 
					  exec {
 | 
				
			||||||
    command = "sh -c 'systemctl reload consul || true'"
 | 
					    command = "sh -c 'systemctl reload consul || true'"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
template {
 | 
					 | 
				
			||||||
  source          = "{{ consul_root_dir }}/consul-template/agent.key.tpl"
 | 
					 | 
				
			||||||
  left_delimiter  = "[["
 | 
					 | 
				
			||||||
  right_delimiter = "]]"
 | 
					 | 
				
			||||||
  destination     = "{{ consul_conf.tls.defaults.key_file }}"
 | 
					 | 
				
			||||||
  perms           = 0640
 | 
					 | 
				
			||||||
  exec {
 | 
					 | 
				
			||||||
    command = "sh -c 'chgrp {{ consul_user }} {{ consul_conf.tls.defaults.key_file }} && systemctl reload consul || true'"
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template {
 | 
					 | 
				
			||||||
  source          = "{{ consul_root_dir }}/consul-template/cli.crt.tpl"
 | 
					 | 
				
			||||||
  left_delimiter  = "[["
 | 
					 | 
				
			||||||
  right_delimiter = "]]"
 | 
					 | 
				
			||||||
  destination     = "{{ consul_root_dir }}/tls/cli.crt"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template {
 | 
					 | 
				
			||||||
  source          = "{{ consul_root_dir }}/consul-template/cli.key.tpl"
 | 
					 | 
				
			||||||
  left_delimiter  = "[["
 | 
					 | 
				
			||||||
  right_delimiter = "]]"
 | 
					 | 
				
			||||||
  destination     = "{{ consul_root_dir }}/tls/cli.key"
 | 
					 | 
				
			||||||
  perms           = 0640
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
{% endif %}
 | 
					 | 
				
			||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if consul_vault_secrets.tokens.enabled %}
 | 
					{% if consul_vault_secrets.tokens.enabled %}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,6 +89,7 @@ acl {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if consul_conf.tls.enabled %}
 | 
					{% if consul_conf.tls.enabled %}
 | 
				
			||||||
 | 
					{% if consul_conf.server %}
 | 
				
			||||||
# TLS settings
 | 
					# TLS settings
 | 
				
			||||||
tls {
 | 
					tls {
 | 
				
			||||||
{% for section in ['defaults', 'grpc', 'https', 'internal_rpc'] %}
 | 
					{% for section in ['defaults', 'grpc', 'https', 'internal_rpc'] %}
 | 
				
			||||||
@@ -110,7 +111,6 @@ tls {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# auto_encrypt, to distribute certificates from servers to clients
 | 
					# auto_encrypt, to distribute certificates from servers to clients
 | 
				
			||||||
{% if consul_conf.server %}
 | 
					 | 
				
			||||||
auto_encrypt {
 | 
					auto_encrypt {
 | 
				
			||||||
  allow_tls = true
 | 
					  allow_tls = true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,6 @@ After=network-online.target
 | 
				
			|||||||
ConditionFileNotEmpty={{ consul_root_dir }}/etc/consul.hcl
 | 
					ConditionFileNotEmpty={{ consul_root_dir }}/etc/consul.hcl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[Service]
 | 
					[Service]
 | 
				
			||||||
Type=notify
 | 
					 | 
				
			||||||
EnvironmentFile=-{{ consul_root_dir }}/etc/consul.env
 | 
					EnvironmentFile=-{{ consul_root_dir }}/etc/consul.env
 | 
				
			||||||
User={{ consul_user }}
 | 
					User={{ consul_user }}
 | 
				
			||||||
Group={{ consul_user }}
 | 
					Group={{ consul_user }}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -229,7 +229,7 @@ nomad_services: "{{ nomad_base_services | combine(nomad_extra_services, recursiv
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# When using vault to setup TLS for Nomad
 | 
					# When using vault to setup TLS for Nomad
 | 
				
			||||||
nomad_base_vault_secrets:
 | 
					nomad_base_vault_secrets:
 | 
				
			||||||
  vault_address: "{{ nomad_conf.vault.address | default(omit) }}"
 | 
					  vault_address: "{{ nomad_conf.vault.address | default('https://active.vault.service.consul:8200') }}"
 | 
				
			||||||
  # Token to use to issue certificates
 | 
					  # Token to use to issue certificates
 | 
				
			||||||
  # token: XXXXXXXXX
 | 
					  # token: XXXXXXXXX
 | 
				
			||||||
  pki:
 | 
					  pki:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -119,36 +119,25 @@
 | 
				
			|||||||
  when: nomad_vault_secrets.pki.enabled or nomad_vault_secrets.tokens.enabled
 | 
					  when: nomad_vault_secrets.pki.enabled or nomad_vault_secrets.tokens.enabled
 | 
				
			||||||
  tags: nomad
 | 
					  tags: nomad
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Deploy consul-template agent cert template
 | 
					- name: Deploy consul-template agent bundle template
 | 
				
			||||||
  template: src=agent_cert.tpl.j2 dest={{ nomad_root_dir }}/consul-template/{{ item.where }} owner=root group=root
 | 
					  template: src=agent_bundle.pem.tpl.j2 dest={{ nomad_root_dir }}/consul-template/agent_bundle.pem.tpl 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
 | 
					  notify: restart consul-template-nomad
 | 
				
			||||||
  when: nomad_vault_secrets.pki.enabled
 | 
					  when: nomad_vault_secrets.pki.enabled
 | 
				
			||||||
  tags: nomad
 | 
					  tags: nomad
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Deploy consul-template cli cert template
 | 
					- name: Deploy consul-template cli bundle template
 | 
				
			||||||
  template: src=cli_cert.tpl.j2 dest={{ nomad_root_dir }}/consul-template/{{ item.where }} owner=root group=root
 | 
					  template: src=cli_bundle.pem.tpl.j2 dest={{ nomad_root_dir }}/consul-template/cli_bundle.pem.tpl owner=root group=root
 | 
				
			||||||
  loop:
 | 
					 | 
				
			||||||
    - what: certificate
 | 
					 | 
				
			||||||
      where: cli.crt.tpl
 | 
					 | 
				
			||||||
    - what: private_key
 | 
					 | 
				
			||||||
      where: cli.key.tpl
 | 
					 | 
				
			||||||
  notify: restart consul-template-nomad
 | 
					  notify: restart consul-template-nomad
 | 
				
			||||||
  when: nomad_vault_secrets.pki.enabled and nomad_conf.server.enabled
 | 
					  when: nomad_vault_secrets.pki.enabled and nomad_conf.server.enabled
 | 
				
			||||||
  tags: nomad
 | 
					  tags: nomad
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Set ACL on the TLS dir
 | 
					- name: Set ACL on the TLS dir
 | 
				
			||||||
  shell: |
 | 
					  shell: |
 | 
				
			||||||
    setfacl -R -b -x {{ nomad_root_dir }}/tls
 | 
					    setfacl -R -b -k {{ nomad_root_dir }}/tls
 | 
				
			||||||
    {% if nomad_admin_groups | length > 0 %}
 | 
					    {% if nomad_admin_groups | length > 0 %}
 | 
				
			||||||
    setfacl -R -m {% for group in nomad_admin_groups %}g:{{ group }}:rX{{ ',' if not loop.last }}{% endfor %} {{ nomad_root_dir }}/tls
 | 
					    setfacl -m {% for group in nomad_admin_groups %}g:{{ group }}:rx{{ ',' if not loop.last }}{% endfor %} {{ nomad_root_dir }}/tls
 | 
				
			||||||
    setfacl -R -m {% for group in nomad_admin_groups %}d:g:{{ group }}:rX{{ ',' if not loop.last }}{% endfor %} {{ nomad_root_dir }}/tls
 | 
					    setfacl -m {% for group in nomad_admin_groups %}d:g:{{ group }}:r{{ ',' if not loop.last }}{% endfor %} {{ nomad_root_dir }}/tls
 | 
				
			||||||
 | 
					    setfacl -m {% for group in nomad_admin_groups %}g:{{ group }}:r{{ ',' if not loop.last }}{% endfor %} {{ nomad_root_dir }}/tls/*
 | 
				
			||||||
    {% endif %}
 | 
					    {% endif %}
 | 
				
			||||||
  changed_when: False
 | 
					  changed_when: False
 | 
				
			||||||
  failed_when: False # Do not fail if eg, the FS doesn't support ACL
 | 
					  failed_when: False # Do not fail if eg, the FS doesn't support ACL
 | 
				
			||||||
@@ -159,14 +148,7 @@
 | 
				
			|||||||
  tags: nomad
 | 
					  tags: nomad
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Deploy consul-template consul cert templates
 | 
					- name: Deploy consul-template consul cert templates
 | 
				
			||||||
  template: src=consul_cert.tpl.j2 dest={{ nomad_root_dir }}/consul-template/{{ item.where }} owner=root group=root
 | 
					  template: src=consul_bundle.pem.tpl.j2 dest={{ nomad_root_dir }}/consul-template/consul_bundle.pem.tpl owner=root group=root
 | 
				
			||||||
  loop:
 | 
					 | 
				
			||||||
    - what: certificate
 | 
					 | 
				
			||||||
      where: consul.crt.tpl
 | 
					 | 
				
			||||||
    - what: private_key
 | 
					 | 
				
			||||||
      where: consul.key.tpl
 | 
					 | 
				
			||||||
    - what: issuing_ca
 | 
					 | 
				
			||||||
      where: consul_ca.crt.tpl
 | 
					 | 
				
			||||||
  notify: restart consul-template-nomad
 | 
					  notify: restart consul-template-nomad
 | 
				
			||||||
  when: nomad_vault_secrets.consul_pki.enabled and nomad_conf.consul.ssl
 | 
					  when: nomad_vault_secrets.consul_pki.enabled and nomad_conf.consul.ssl
 | 
				
			||||||
  tags: nomad
 | 
					  tags: nomad
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								roles/nomad/templates/agent_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								roles/nomad/templates/agent_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					[[ with pkiCert "{{ 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 %} ]]
 | 
				
			||||||
 | 
					[[ .CA ]]
 | 
				
			||||||
 | 
					[[ .Cert ]]
 | 
				
			||||||
 | 
					[[ .Key ]]
 | 
				
			||||||
 | 
					[[ .CA | writeToFile "{{ nomad_conf.tls.ca_file }}" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ .Cert | writeToFile "{{ nomad_conf.tls.cert_file }}" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ .Key | writeToFile "{{ nomad_conf.tls.key_file }}" "root" "{{ nomad_user }}" "0640" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
 | 
					[[ with secret "{{ nomad_vault_secrets.pki.path }}/cert/ca" ]]
 | 
				
			||||||
 | 
					[[ .Data.certificate | writeToFile "{{ nomad_conf.tls.cert_file }}" "" "" "0644" "append,newline" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
@@ -1,8 +0,0 @@
 | 
				
			|||||||
[[ 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_secrets.pki.path }}/cert/ca" ]]
 | 
					 | 
				
			||||||
[[ .Data.certificate ]]
 | 
					 | 
				
			||||||
[[ end ]]
 | 
					 | 
				
			||||||
{% endif %}
 | 
					 | 
				
			||||||
							
								
								
									
										7
									
								
								roles/nomad/templates/cli_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								roles/nomad/templates/cli_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					[[ with pkiCert "{{ nomad_vault_secrets.pki.path }}/issue/{{ nomad_vault_secrets.pki.role }}" "common_name=cli-{{ ansible_fqdn | regex_replace('\\.', '-') }}.{{ nomad_conf.region | default('global') }}.nomad" ]]
 | 
				
			||||||
 | 
					[[ .CA ]]
 | 
				
			||||||
 | 
					[[ .Cert ]]
 | 
				
			||||||
 | 
					[[ .Key ]]
 | 
				
			||||||
 | 
					[[ .Cert | writeToFile "{{ nomad_root_dir }}/tls/cli.crt" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ .Key | writeToFile "{{ nomad_root_dir }}/tls/cli.key" "root" "root" "0640" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
@@ -1,3 +0,0 @@
 | 
				
			|||||||
[[ 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 ]]
 | 
					 | 
				
			||||||
@@ -4,92 +4,40 @@ vault {
 | 
				
			|||||||
  unwrap_token = false
 | 
					  unwrap_token = false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Sleep 10 sec before sending nomad service a reload to prevent it from crashing as
 | 
					# Sleep 25 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
 | 
					# Nomad doesn't support getting a reload while it's still initializing
 | 
				
			||||||
{% if nomad_vault_secrets.pki.enabled %}
 | 
					{% if nomad_vault_secrets.pki.enabled %}
 | 
				
			||||||
template {
 | 
					template {
 | 
				
			||||||
  source          = "{{ nomad_root_dir }}/consul-template/agent.crt.tpl"
 | 
					  source          = "{{ nomad_root_dir }}/consul-template/agent_bundle.pem.tpl"
 | 
				
			||||||
  left_delimiter  = "[["
 | 
					  left_delimiter  = "[["
 | 
				
			||||||
  right_delimiter = "]]"
 | 
					  right_delimiter = "]]"
 | 
				
			||||||
  destination     = "{{ nomad_conf.tls.cert_file }}"
 | 
					  destination     = "{{ nomad_root_dir }}/tls/agent_bundle.pem"
 | 
				
			||||||
  perms           = 0644
 | 
					 | 
				
			||||||
  exec {
 | 
					 | 
				
			||||||
    command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template {
 | 
					 | 
				
			||||||
  source          = "{{ nomad_root_dir }}/consul-template/agent.key.tpl"
 | 
					 | 
				
			||||||
  left_delimiter  = "[["
 | 
					 | 
				
			||||||
  right_delimiter = "]]"
 | 
					 | 
				
			||||||
  destination     = "{{ nomad_conf.tls.key_file }}"
 | 
					 | 
				
			||||||
  perms           = 0640
 | 
					  perms           = 0640
 | 
				
			||||||
  exec {
 | 
					  exec {
 | 
				
			||||||
    command = ["sh", "-c", "chgrp {{ nomad_user }} {{ nomad_conf.tls.key_file }} && sleep 10 && systemctl reload nomad || true"]
 | 
					    command = "sh -c 'sleep 25 && systemctl reload nomad || true'"
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template {
 | 
					 | 
				
			||||||
  source          = "{{ nomad_root_dir }}/consul-template/ca.crt.tpl"
 | 
					 | 
				
			||||||
  left_delimiter  = "[["
 | 
					 | 
				
			||||||
  right_delimiter = "]]"
 | 
					 | 
				
			||||||
  destination     = "{{ nomad_conf.tls.ca_file }}"
 | 
					 | 
				
			||||||
  perms           = 0644
 | 
					 | 
				
			||||||
  exec {
 | 
					 | 
				
			||||||
    command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if nomad_conf.server.enabled %}
 | 
					{% if nomad_conf.server.enabled %}
 | 
				
			||||||
template {
 | 
					template {
 | 
				
			||||||
  source          = "{{ nomad_root_dir }}/consul-template/cli.crt.tpl"
 | 
					  source          = "{{ nomad_root_dir }}/consul-template/cli_bundle.pem.tpl"
 | 
				
			||||||
 | 
					  destination     = "{{ nomad_root_dir }}/tls/cli_bundle.pem"
 | 
				
			||||||
  left_delimiter  = "[["
 | 
					  left_delimiter  = "[["
 | 
				
			||||||
  right_delimiter = "]]"
 | 
					  right_delimiter = "]]"
 | 
				
			||||||
  destination     = "{{ nomad_root_dir }}/tls/cli.crt"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template {
 | 
					 | 
				
			||||||
  source          = "{{ nomad_root_dir }}/consul-template/cli.key.tpl"
 | 
					 | 
				
			||||||
  left_delimiter  = "[["
 | 
					 | 
				
			||||||
  right_delimiter = "]]"
 | 
					 | 
				
			||||||
  destination     = "{{ nomad_root_dir }}/tls/cli.key"
 | 
					 | 
				
			||||||
  perms           = 0640
 | 
					  perms           = 0640
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
{% endif %}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if nomad_vault_secrets.consul_pki.enabled and nomad_conf.consul.ssl %}
 | 
					{% if nomad_vault_secrets.consul_pki.enabled and nomad_conf.consul.ssl %}
 | 
				
			||||||
template {
 | 
					template {
 | 
				
			||||||
  source          = "{{ nomad_root_dir }}/consul-template/consul.crt.tpl"
 | 
					  source          = "{{ nomad_root_dir }}/consul-template/consul_bundle.pem.tpl"
 | 
				
			||||||
 | 
					  destination     = "{{ nomad_root_dir }}/tlc/consul_bundle.pem"
 | 
				
			||||||
  left_delimiter  = "[["
 | 
					  left_delimiter  = "[["
 | 
				
			||||||
  right_delimiter = "]]"
 | 
					  right_delimiter = "]]"
 | 
				
			||||||
  destination     = "{{ nomad_conf.consul.cert_file }}"
 | 
					 | 
				
			||||||
  exec {
 | 
					 | 
				
			||||||
    command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template {
 | 
					 | 
				
			||||||
  source          = "{{ nomad_root_dir }}/consul-template/consul.key.tpl"
 | 
					 | 
				
			||||||
  left_delimiter  = "[["
 | 
					 | 
				
			||||||
  right_delimiter = "]]"
 | 
					 | 
				
			||||||
  destination     = "{{ nomad_conf.consul.key_file }}"
 | 
					 | 
				
			||||||
  perms           = 0640
 | 
					  perms           = 0640
 | 
				
			||||||
  exec {
 | 
					  exec {
 | 
				
			||||||
    command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
 | 
					    command = "sh -c 'sleep 25 && systemctl reload nomad || true'"
 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
template {
 | 
					 | 
				
			||||||
  source          = "{{ nomad_root_dir }}/consul-template/consul_ca.crt.tpl"
 | 
					 | 
				
			||||||
  left_delimiter  = "[["
 | 
					 | 
				
			||||||
  right_delimiter = "]]"
 | 
					 | 
				
			||||||
  destination     = "{{ nomad_conf.consul.ca_file }}"
 | 
					 | 
				
			||||||
  perms           = 0644
 | 
					 | 
				
			||||||
  exec {
 | 
					 | 
				
			||||||
    command = "sh -c 'sleep 10 && systemctl reload nomad || true'"
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
 | 
					{% endif %}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										11
									
								
								roles/nomad/templates/consul_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								roles/nomad/templates/consul_bundle.pem.tpl.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					[[ with pkiCert "{{ 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 %} ]]
 | 
				
			||||||
 | 
					[[ .CA ]]
 | 
				
			||||||
 | 
					[[ .Cert ]]
 | 
				
			||||||
 | 
					[[ .Key ]]
 | 
				
			||||||
 | 
					[[ .CA | writeToFile "{{ nomad_conf.consul.ca_file }}" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ .Cert | writeToFile "{{ nomad_conf.consul.cert_file }}" "root" "root" "0644" ]]
 | 
				
			||||||
 | 
					[[ .Key | writeToFile "{{ nomad_conf.consul.key_file }}" "root" "{{ nomad_user }}" "0640" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
 | 
					[[ with secret "{{ nomad_vault_secrets.consul_pki.root_path }}/cert/ca" ]]
 | 
				
			||||||
 | 
					[[ .Data.certificate | writeToFile "{{ nomad_conf.consul.ca_file }}" "root" "root" "0644" "append,newline" ]]
 | 
				
			||||||
 | 
					[[ end ]]
 | 
				
			||||||
@@ -1,8 +0,0 @@
 | 
				
			|||||||
[[ 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_secrets.consul_pki.root_path }}/cert/ca" ]]
 | 
					 | 
				
			||||||
[[ .Data.certificate ]]
 | 
					 | 
				
			||||||
[[ end ]]
 | 
					 | 
				
			||||||
{% endif %}
 | 
					 | 
				
			||||||
@@ -18,7 +18,6 @@ User={{ nomad_user }}
 | 
				
			|||||||
Group={{ nomad_user }}
 | 
					Group={{ nomad_user }}
 | 
				
			||||||
ExecStart={{ nomad_root_dir }}/bin/nomad agent -config={{ nomad_root_dir }}/etc/
 | 
					ExecStart={{ nomad_root_dir }}/bin/nomad agent -config={{ nomad_root_dir }}/etc/
 | 
				
			||||||
ExecReload=/bin/kill --signal HUP $MAINPID
 | 
					ExecReload=/bin/kill --signal HUP $MAINPID
 | 
				
			||||||
SuccessExitStatus=1
 | 
					 | 
				
			||||||
Restart=on-failure
 | 
					Restart=on-failure
 | 
				
			||||||
LimitNOFILE=65536
 | 
					LimitNOFILE=65536
 | 
				
			||||||
LimitNPROC=infinity
 | 
					LimitNPROC=infinity
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user