Playbooks to a new Lilik
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.

110 lines
2.6 KiB

  1. ---
  2. - include: 'roles/service/tasks/main.yaml'
  3. vars:
  4. service_name: 'ssh'
  5. service_packages:
  6. - 'openssh-server'
  7. - 'openssh-sftp-server'
  8. - name: 'update user ca certs'
  9. template:
  10. src: 'user_ca.pub.j2'
  11. dest: '/etc/ssh/user_ca.pub'
  12. notify: 'restart ssh'
  13. - name: 'validate ssh cert if present'
  14. ssh_cert:
  15. register: ssh_verification
  16. ignore_errors: yes
  17. - debug:
  18. var: ssh_verification
  19. verbosity: 2
  20. - block:
  21. - name: 'generate host cert request'
  22. cert_request:
  23. host: '{{ server_fqdn }}'
  24. path: '/etc/ssh/ssh_host_ed25519_key.pub'
  25. proto: 'ssh'
  26. register: ca_request
  27. - name: 'start sign request'
  28. include: 'ca-dialog.yaml'
  29. vars:
  30. ansible_connection: 'ssh'
  31. - debug:
  32. var: request_result
  33. verbosity: 2
  34. - set_fact:
  35. request_output: '{{ request_result.stdout | from_json }}'
  36. - debug:
  37. var: request_output
  38. verbosity: 2
  39. - name: 'generate get request'
  40. set_fact:
  41. ca_request:
  42. type: 'get_certificate'
  43. requestID: '{{ request_output.requestID }}'
  44. - debug:
  45. var: ca_request
  46. verbosity: 2
  47. - debug:
  48. msg: 'Please manualy confirm sign request with id {{ request_output.requestID }}'
  49. - name: 'wait for cert'
  50. include: 'ca-dialog.yaml'
  51. vars:
  52. ansible_connection: 'ssh'
  53. - debug:
  54. var: request_result
  55. verbosity: 2
  56. - set_fact:
  57. cert_key: '{{ request_result.stdout | string | from_json }}'
  58. - name: 'write certificate to container'
  59. copy:
  60. content: '{{ cert_key.result }}'
  61. dest: '/etc/ssh/ssh_host_ed25519_key-cert.pub'
  62. register: set_pub_key
  63. notify: 'restart ssh'
  64. when: ssh_verification.failed
  65. - name: 'add certificate to sshd config'
  66. lineinfile:
  67. line: 'HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub'
  68. dest: '/etc/ssh/sshd_config'
  69. regexp: '^HostCertificate *'
  70. notify: 'restart ssh'
  71. - name: 'trust user ca key'
  72. lineinfile:
  73. line: 'TrustedUserCAKeys /etc/ssh/user_ca.pub'
  74. dest: '/etc/ssh/sshd_config'
  75. regexp: '^TrustedUserCAKeys *'
  76. notify: 'restart ssh'
  77. - name: 'permit root login only with certificate'
  78. lineinfile:
  79. line: 'PermitRootLogin without-password'
  80. dest: '/etc/ssh/sshd_config'
  81. regexp: '^PermitRootLogin *'
  82. notify: 'restart ssh'
  83. - meta: 'flush_handlers'
  84. - name: 'waiting for ssh on {{ inventory_hostname }} to start'
  85. wait_for:
  86. host: '{{ hostvars | ip_from_inventory(inventory_hostname) }}'
  87. port: 22
  88. timeout: 30
  89. delegate_to: '{{ inventory_hostname }}'
  90. delegate_facts: true