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.

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