Saltstack Official OpenSSH 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.

70 lines
2.0KB

  1. {% from "openssh/map.jinja" import openssh with context %}
  2. include:
  3. - openssh
  4. {% if salt['pillar.get']('sshd_config', False) %}
  5. sshd_config:
  6. file.managed:
  7. - name: {{ openssh.sshd_config }}
  8. - source: {{ openssh.sshd_config_src }}
  9. - template: jinja
  10. - user: root
  11. - mode: 644
  12. - watch_in:
  13. - service: openssh
  14. {% endif %}
  15. {% if salt['pillar.get']('ssh_config', False) %}
  16. ssh_config:
  17. file.managed:
  18. - name: {{ openssh.ssh_config }}
  19. - source: {{ openssh.ssh_config_src }}
  20. - template: jinja
  21. - user: root
  22. - mode: 644
  23. {% endif %}
  24. {% for keyType in ['ecdsa', 'dsa', 'rsa', 'ed25519'] %}
  25. {% if salt['pillar.get']('openssh:generate_' ~ keyType ~ '_keys', False) %}
  26. ssh_generate_host_{{ keyType }}_key:
  27. cmd.run:
  28. {%- if salt['pillar.get']('openssh:generate_' ~ keyType ~ '_size', False) %}
  29. {%- set keySize = salt['pillar.get']('openssh:generate_' ~ keyType ~ '_size', 4096) %}
  30. - name: ssh-keygen -t {{ keyType }} -b {{ keySize }} -N '' -f /etc/ssh/ssh_host_{{ keyType }}_key
  31. {%- else %}
  32. - name: ssh-keygen -t {{ keyType }} -N '' -f /etc/ssh/ssh_host_{{ keyType }}_key
  33. {%- endif %}
  34. - creates: /etc/ssh/ssh_host_{{ keyType }}_key
  35. - user: root
  36. {% elif salt['pillar.get']('openssh:absent_' ~ keyType ~ '_keys', False) %}
  37. ssh_host_{{ keyType }}_key:
  38. file.absent:
  39. - name: /etc/ssh/ssh_host_{{ keyType }}_key
  40. ssh_host_{{ keyType }}_key.pub:
  41. file.absent:
  42. - name: /etc/ssh/ssh_host_{{ keyType }}_key.pub
  43. {% elif salt['pillar.get']('openssh:provide_' ~ keyType ~ '_keys', False) %}
  44. ssh_host_{{ keyType }}_key:
  45. file.managed:
  46. - name: /etc/ssh/ssh_host_{{ keyType }}_key
  47. - contents_pillar: 'openssh:{{ keyType }}:private_key'
  48. - user: root
  49. - mode: 600
  50. - require_in:
  51. - service: {{ openssh.service }}
  52. ssh_host_{{ keyType }}_key.pub:
  53. file.managed:
  54. - name: /etc/ssh/ssh_host_{{ keyType }}_key.pub
  55. - contents_pillar: 'openssh:{{ keyType }}:public_key'
  56. - user: root
  57. - mode: 600
  58. - require_in:
  59. - service: {{ openssh.service }}
  60. {% endif %}
  61. {% endfor %}