main.yml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. - name: "create repository's root directory {{ borgbackup_sshd_repository_path }}"
  2. file:
  3. path: '{{ borgbackup_sshd_repository_path }}'
  4. state: directory
  5. mode: u=rwx,go=x
  6. register: _repo_dir
  7. - name: fetch host's architecture to select container image
  8. setup:
  9. gather_subset: min
  10. when: not borgbackup_sshd_container_image and ansible_architecture is not defined
  11. - docker_container:
  12. name: '{{ borgbackup_sshd_container_name }}'
  13. image: >-
  14. {{ borgbackup_sshd_container_image or _default_container_images[ansible_architecture] }}
  15. env:
  16. SSH_CLIENT_PUBLIC_KEYS: "{{ borgbackup_sshd_client_public_keys }}"
  17. SSH_CLIENT_PUBLIC_KEYS_APPEND_ONLY: "{{ borgbackup_sshd_client_public_keys_append_only }}"
  18. read_only: yes
  19. mounts:
  20. - type: volume
  21. source: '{{ borgbackup_sshd_container_name }}_host_keys'
  22. target: /etc/ssh/host_keys
  23. read_only: no
  24. - type: bind
  25. source: '{{ _repo_dir.path }}'
  26. target: /repository
  27. read_only: no
  28. - type: tmpfs
  29. target: /home/borg/.ssh # authorized_keys
  30. tmpfs_size: 16k
  31. tmpfs_mode: '1777'
  32. - type: tmpfs
  33. # > FileNotFoundError: [Errno 2] No usable temporary directory found [...]
  34. target: /tmp
  35. tmpfs_size: 1M
  36. tmpfs_mode: '1777'
  37. published_ports: >-
  38. {{ ['0.0.0.0:%d:2200' % borgbackup_sshd_published_port]
  39. if (borgbackup_sshd_published_port is defined) else [] }}
  40. cap_drop: [ALL]
  41. security_opts: [no-new-privileges]
  42. cpu_quota: 8000
  43. cpu_period: 10000
  44. # 64MiB was insufficient for two parallel operations, e.g. `borg create` & `borg list`
  45. memory: 128M
  46. restart_policy: unless-stopped
  47. state: started
  48. register: _container
  49. - name: determine offset of user namespace remapping
  50. stat:
  51. path: '{{ _container.container.ResolvConfPath }}'
  52. register: _container_resolvconf
  53. - name: adapt ownership of repository's root directory
  54. file:
  55. path: '{{ _repo_dir.path }}'
  56. owner: '{{ _container_resolvconf.stat.uid + 100 }}'
  57. - name: wait for host keys
  58. wait_for:
  59. path: "{{ (_container.container.Mounts | items2dict(key_name='Destination', value_name='Source'))['/etc/ssh/host_keys'] }}/{{ item }}.pub"
  60. loop: [rsa, ed25519]
  61. register: _host_keys_files
  62. - name: read host keys
  63. slurp:
  64. src: '{{ item }}'
  65. loop: "{{ _host_keys_files.results | map(attribute='path') | list }}"
  66. register: _host_keys_base64
  67. - name: decode host keys
  68. set_fact:
  69. borgbackup_sshd_host_keys: >-
  70. {{ _host_keys_base64.results | map(attribute='content') | map('b64decode') | map('trim') | list }}