main.yml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. - docker_container:
  2. name: '{{ sftpd_container_name }}'
  3. image: '{{ sftpd_container_image }}'
  4. env:
  5. SSH_CLIENT_PUBLIC_KEYS: "{{ sftpd_client_public_keys }}"
  6. read_only: yes
  7. mounts:
  8. - type: volume
  9. source: '{{ sftpd_container_name }}_host_keys'
  10. target: /etc/ssh/host_keys
  11. read_only: no
  12. - type: volume
  13. source: '{{ sftpd_data_volume_name }}'
  14. target: /data
  15. read_only: yes
  16. - type: tmpfs
  17. target: /home/nonroot/.ssh # authorized_keys
  18. tmpfs_size: 16k
  19. tmpfs_mode: '1777'
  20. network_mode: '{{ sftpd_network_mode | default(omit) }}'
  21. published_ports: >-
  22. {{ ['0.0.0.0:%d:2200' % sftpd_published_port]
  23. if sftpd_published_port else [] }}
  24. cap_drop: [ALL]
  25. # ChrootDirectory
  26. capabilities: [SETUID, SETGID, SYS_CHROOT]
  27. security_opts: [no-new-privileges]
  28. cpus: 0.8
  29. memory: 64M
  30. restart_policy: unless-stopped
  31. state: started
  32. register: _container
  33. - name: wait for host keys
  34. wait_for:
  35. path: >-
  36. {{ (_container.container.Mounts
  37. | items2dict(key_name='Destination', value_name='Source'))
  38. ['/etc/ssh/host_keys'] }}/{{ item }}.pub
  39. loop: [rsa, ed25519]
  40. register: _host_keys_files
  41. - name: read host keys
  42. slurp:
  43. src: '{{ item }}'
  44. loop: "{{ _host_keys_files.results | map(attribute='path') | list }}"
  45. register: _host_keys_base64
  46. - name: decode host keys
  47. set_fact:
  48. sftpd_host_keys: >-
  49. {{ _host_keys_base64.results | map(attribute='content')
  50. | map('b64decode') | map('trim') | list }}