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.

112 lines
2.7 KiB

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