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.

116 lines
2.8 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: lookup user ca key
  11. set_fact:
  12. user_ca_key: "{{ lookup('file', 'lilik_ca_s1.pub') }}"
  13. - name: Update container user CA key
  14. copy:
  15. content: "{{ user_ca_key }}"
  16. dest: "/etc/ssh/user_ca.pub"
  17. notify: restart ssh
  18. - name: Validate SSH host certificate if any
  19. ssh_cert:
  20. register: ssh_verification
  21. ignore_errors: yes
  22. - debug:
  23. var: ssh_verification
  24. verbosity: 2
  25. - block:
  26. - name: Generate host request
  27. cert_request:
  28. host: "{{ server_fqdn }}"
  29. path: "/etc/ssh/ssh_host_ed25519_key.pub"
  30. proto: "ssh"
  31. register: ca_request
  32. - name: start sign request
  33. include: ca-dialog.yaml
  34. vars:
  35. ansible_connection: ssh
  36. - debug:
  37. var: request_result
  38. verbosity: 2
  39. - set_fact:
  40. request_output: "{{ request_result.stdout | from_json }}"
  41. - debug:
  42. var: request_output
  43. verbosity: 2
  44. - name: generate get request
  45. set_fact:
  46. ca_request:
  47. type: 'get_certificate'
  48. requestID: '{{ request_output.requestID }}'
  49. - debug:
  50. var: ca_request
  51. verbosity: 2
  52. - debug:
  53. msg: "Please manualy confirm sign request with id {{ request_output.requestID }}"
  54. - name: wait for cert
  55. include: ca-dialog.yaml
  56. vars:
  57. ansible_connection: ssh
  58. - debug:
  59. var: request_result
  60. verbosity: 2
  61. - set_fact:
  62. cert_key: "{{ request_result.stdout | string | from_json }}"
  63. - name: Write certificate to container
  64. copy:
  65. content: "{{ cert_key.result }}"
  66. dest: "/etc/ssh/ssh_host_ed25519_key-cert.pub"
  67. register: set_pub_key
  68. notify: restart ssh
  69. when: ssh_verification.failed
  70. - name: add certificate to sshd config
  71. lineinfile:
  72. line: 'HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub'
  73. dest: '/etc/ssh/sshd_config'
  74. regexp: '^HostCertificate *'
  75. notify: restart ssh
  76. - name: trust user ca key
  77. lineinfile:
  78. line: 'TrustedUserCAKeys /etc/ssh/user_ca.pub'
  79. dest: '/etc/ssh/sshd_config'
  80. regexp: '^TrustedUserCAKeys *'
  81. notify: restart ssh
  82. - name: permit root login only with certificate
  83. lineinfile:
  84. line: 'PermitRootLogin without-password'
  85. dest: '/etc/ssh/sshd_config'
  86. regexp: '^PermitRootLogin *'
  87. notify: restart ssh
  88. - meta: flush_handlers
  89. - name: "waiting for ssh on {{ ansible_docker_extra_args | default(inventory_hostname) }} to start"
  90. wait_for:
  91. host: "{{ hostvars | ip_from_inventory(inventory_hostname) }}"
  92. port: 22
  93. timeout: 30
  94. delegate_to: "{{ inventory_hostname }}"
  95. delegate_facts: True