init.sls 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # SSL Certificates
  3. #
  4. openssl:
  5. pkg.installed:
  6. - name: openssl
  7. c_rehash:
  8. cmd.wait:
  9. - name: /usr/bin/c_rehash >/dev/null 2>/dev/null
  10. - watch: []
  11. # FFHO internal CA
  12. /etc/ssl/certs/ffho-cacert.pem:
  13. file.managed:
  14. - source: salt://certs/ffho-cacert.pem
  15. - user: root
  16. - group: root
  17. - mode: 644
  18. - watch_in:
  19. - cmd: c_rehash
  20. # StartSSL Class1intermediate CA certificate
  21. /etc/ssl/certs/StartSSL_Class1_CA.pem:
  22. file.managed:
  23. - source: salt://certs/StartSSL_Class1_CA.pem
  24. - user: root
  25. - group: root
  26. - mode: 644
  27. - watch_in:
  28. - cmd: c_rehash
  29. # StartSSL Class2 intermediate CA certificate
  30. /etc/ssl/certs/StartSSL_Class2_CA.pem:
  31. file.managed:
  32. - source: salt://certs/StartSSL_Class2_CA.pem
  33. - user: root
  34. - group: root
  35. - mode: 644
  36. - watch_in:
  37. - cmd: c_rehash
  38. # Are there any certificates defined or referenced in the node pillar?
  39. {% for cn in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':certs', {})|sort %}
  40. {% set pillar_name = None %}
  41. {% set cert_config = salt['pillar.get']('nodes:' ~ grains['id'] ~ ':certs:' ~ cn) %}
  42. {# "cert" and "privkey" provided in node config? #}
  43. {% if 'cert' in cert_config and 'privkey' in cert_config %}
  44. {% set pillar_name = 'nodes:' ~ grains['id'] ~ ':certs:' ~ cn %}
  45. {# <cn> only referenced in node config and cert/privkey stored in "cert" pillar? #}
  46. {% elif cert_config.get ('install', False) == True %}
  47. {% set pillar_name = 'cert:' ~ cn %}
  48. {% endif %}
  49. {% if pillar_name != None %}
  50. /etc/ssl/certs/{{ cn }}.cert.pem:
  51. file.managed:
  52. {% if salt['pillar.get'](pillar_name ~ ':cert') == "file" %}
  53. - source: salt://certs/certs/{{ cn }}.cert.pem
  54. {% else %}
  55. - contents_pillar: {{ pillar_name }}:cert
  56. {% endif %}
  57. - user: root
  58. - group: root
  59. - mode: 644
  60. /etc/ssl/private/{{ cn }}.key.pem:
  61. file.managed:
  62. - contents_pillar: {{ pillar_name }}:privkey
  63. - user: root
  64. - group: root
  65. - mode: 400
  66. {% endif %}
  67. {% endfor %}