main.yml 2.2 KB

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