2017-07-11 11:31:17 +02:00
{% from 'nginx/ng/map.jinja' import nginx with context %}
2015-06-23 21:17:52 +02:00
include:
- nginx.ng.service
2017-07-31 20:51:58 +02:00
{% set certificates_path = salt['pillar.get']('nginx:ng:certificates_path', '/etc/nginx/ssl') %}
2016-09-19 17:35:30 +02:00
2017-12-21 04:31:49 +01:00
{%- for dh_param, value in salt['pillar.get']('nginx:ng:dh_param', {}).items() %}
2017-07-11 12:19:47 +02:00
{%- if value is string %}
create_nginx_dhparam_{{ dh_param }}_key:
2016-09-19 17:35:30 +02:00
file.managed:
2017-07-11 12:19:47 +02:00
- name: {{ certificates_path }}/{{ dh_param }}
- contents_pillar: nginx:ng:dh_param:{{ dh_param }}
2016-09-19 17:35:30 +02:00
- makedirs: True
2017-07-11 11:44:40 +02:00
- watch_in:
- service: nginx_service
2017-07-11 12:19:47 +02:00
{%- else %}
generate_nginx_dhparam_{{ dh_param }}_key:
2017-07-11 11:31:17 +02:00
pkg.installed:
- name: {{ nginx.lookup.openssl_package }}
2016-09-19 17:35:30 +02:00
file.directory:
- name: {{ certificates_path }}
- makedirs: True
cmd.run:
2017-07-11 12:19:47 +02:00
- name: openssl dhparam -out {{ dh_param }} {{ value.get('keysize', 2048) }}
2016-09-19 17:35:30 +02:00
- cwd: {{ certificates_path }}
2017-07-11 12:19:47 +02:00
- creates: {{ certificates_path }}/{{ dh_param }}
2017-07-11 11:44:40 +02:00
- watch_in:
- service: nginx_service
2017-07-11 12:19:47 +02:00
{%- endif %}
{%- endfor %}
2016-09-19 17:35:30 +02:00
2015-06-23 21:17:52 +02:00
{%- for domain in salt['pillar.get']('nginx:ng:certificates', {}).keys() %}
nginx_{{ domain }}_ssl_certificate:
file.managed:
2017-07-31 20:51:58 +02:00
- name: {{ certificates_path }}/{{ domain }}.crt
2015-06-23 21:17:52 +02:00
- makedirs: True
2018-10-04 16:26:37 +02:00
{% if salt['pillar.get']("nginx:ng:certificates:{}:public_cert_pillar".format(domain)) %}
- contents_pillar: {{salt['pillar.get']('nginx:ng:certificates:{}:public_cert_pillar'.format(domain))}}
{% else %}
2015-06-23 21:17:52 +02:00
- contents_pillar: nginx:ng:certificates:{{ domain }}:public_cert
2018-10-04 16:26:37 +02:00
{% endif %}
2015-06-23 21:17:52 +02:00
- watch_in:
- service: nginx_service
2018-10-04 16:26:37 +02:00
{% if salt['pillar.get']("nginx:ng:certificates:{}:private_key".format(domain)) or salt['pillar.get']("nginx:ng:certificates:{}:private_key_pillar".format(domain))%}
2015-06-23 21:17:52 +02:00
nginx_{{ domain }}_ssl_key:
file.managed:
2017-07-31 20:51:58 +02:00
- name: {{ certificates_path }}/{{ domain }}.key
2015-06-23 21:17:52 +02:00
- mode: 600
- makedirs: True
2018-10-04 16:26:37 +02:00
{% if salt['pillar.get']("nginx:ng:certificates:{}:private_key_pillar".format(domain)) %}
- contents_pillar: {{salt['pillar.get']('nginx:ng:certificates:{}:private_key_pillar'.format(domain))}}
{% else %}
2015-06-23 21:17:52 +02:00
- contents_pillar: nginx:ng:certificates:{{ domain }}:private_key
2018-10-04 16:26:37 +02:00
{% endif %}
2015-06-23 21:17:52 +02:00
- watch_in:
- service: nginx_service
2016-10-12 10:52:17 +02:00
{% endif %}
2015-06-23 21:17:52 +02:00
{%- endfor %}