Saltstack Official Nginx Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

certificates.sls 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {% from 'nginx/map.jinja' import nginx with context %}
  2. include:
  3. - nginx.service
  4. {% set certificates_path = salt['pillar.get']('nginx:certificates_path', '/etc/nginx/ssl') %}
  5. prepare_certificates_path_dir:
  6. file.directory:
  7. - name: {{ certificates_path }}
  8. - makedirs: True
  9. {%- for dh_param, value in salt['pillar.get']('nginx:dh_param', {}).items() %}
  10. {%- if value is string %}
  11. create_nginx_dhparam_{{ dh_param }}_key:
  12. file.managed:
  13. - name: {{ certificates_path }}/{{ dh_param }}
  14. - contents_pillar: nginx:dh_param:{{ dh_param }}
  15. - makedirs: True
  16. - require:
  17. - file: prepare_certificates_path_dir
  18. - watch_in:
  19. - service: nginx_service
  20. {%- else %}
  21. generate_nginx_dhparam_{{ dh_param }}_key:
  22. pkg.installed:
  23. - name: {{ nginx.lookup.openssl_package }}
  24. cmd.run:
  25. - name: openssl dhparam -out {{ dh_param }} {{ value.get('keysize', 2048) }}
  26. - cwd: {{ certificates_path }}
  27. - creates: {{ certificates_path }}/{{ dh_param }}
  28. - require:
  29. - file: prepare_certificates_path_dir
  30. - watch_in:
  31. - service: nginx_service
  32. {%- endif %}
  33. {%- endfor %}
  34. {%- for domain in salt['pillar.get']('nginx:certificates', {}).keys() %}
  35. nginx_{{ domain }}_ssl_certificate:
  36. file.managed:
  37. - name: {{ certificates_path }}/{{ domain }}.crt
  38. - makedirs: True
  39. {% if salt['pillar.get']("nginx:certificates:{}:public_cert_pillar".format(domain)) %}
  40. - contents_pillar: {{ salt['pillar.get']('nginx:certificates:{}:public_cert_pillar'.format(domain)) }}
  41. {% else %}
  42. - contents_pillar: nginx:certificates:{{ domain }}:public_cert
  43. {% endif %}
  44. - watch_in:
  45. - service: nginx_service
  46. {% if salt['pillar.get']("nginx:certificates:{}:private_key".format(domain)) or salt['pillar.get']("nginx:certificates:{}:private_key_pillar".format(domain)) %}
  47. nginx_{{ domain }}_ssl_key:
  48. file.managed:
  49. - name: {{ certificates_path }}/{{ domain }}.key
  50. - mode: 600
  51. - makedirs: True
  52. {% if salt['pillar.get']("nginx:certificates:{}:private_key_pillar".format(domain)) %}
  53. - contents_pillar: {{ salt['pillar.get']('nginx:certificates:{}:private_key_pillar'.format(domain)) }}
  54. {% else %}
  55. - contents_pillar: nginx:certificates:{{ domain }}:private_key
  56. {% endif %}
  57. - watch_in:
  58. - service: nginx_service
  59. {% endif %}
  60. {%- endfor %}