main.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # > *Note* that from community.general 3.0.0 on, if `networks_cli_compatible' is `true'
  38. # > and `networks' contains at least one network, the default value for `network_mode'
  39. # will be the name of the first network in the `networks' list.
  40. network_mode: "{{ borgbackup_sshd_network_name | default('default') }}"
  41. networks_cli_compatible: yes
  42. published_ports: >-
  43. {{ ['0.0.0.0:%d:2200' % borgbackup_sshd_published_port]
  44. if (borgbackup_sshd_published_port is defined) else [] }}
  45. cap_drop: [ALL]
  46. security_opts: [no-new-privileges]
  47. cpu_quota: 8000
  48. cpu_period: 10000
  49. # 64MiB was insufficient for two parallel operations, e.g. `borg create` & `borg list`
  50. memory: 128M
  51. restart_policy: unless-stopped
  52. state: started
  53. register: _container
  54. - name: determine offset of user namespace remapping
  55. stat:
  56. path: '{{ _container.container.ResolvConfPath }}'
  57. register: _container_resolvconf
  58. - name: adapt ownership of repository's root directory
  59. file:
  60. path: '{{ _repo_dir.path }}'
  61. owner: '{{ _container_resolvconf.stat.uid + 100 }}'
  62. - name: wait for host keys
  63. wait_for:
  64. path: "{{ (_container.container.Mounts | items2dict(key_name='Destination', value_name='Source'))['/etc/ssh/host_keys'] }}/{{ item }}.pub"
  65. loop: [rsa, ed25519]
  66. register: _host_keys_files
  67. - name: read host keys
  68. slurp:
  69. src: '{{ item }}'
  70. loop: "{{ _host_keys_files.results | map(attribute='path') | list }}"
  71. register: _host_keys_base64
  72. - name: decode host keys
  73. set_fact:
  74. borgbackup_sshd_host_keys: >-
  75. {{ _host_keys_base64.results | map(attribute='content') | map('b64decode') | map('trim') | list }}