main.yml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. - name: 'onion service container :{{ onion_service_virtual_port }} -> {{ onion_service_target }}'
  2. docker_container:
  3. name: '{{ onion_service_container_name }}'
  4. image: '{{ onion_service_container_image }}'
  5. env:
  6. VIRTUAL_PORT: '{{ onion_service_virtual_port | string }}'
  7. TARGET: '{{ onion_service_target }}'
  8. NON_ANONYMOUS_SINGLE_HOP_MODE: "{{ onion_service_non_anonymous_single_hop_mode | string }}"
  9. read_only: yes
  10. mounts:
  11. - type: volume
  12. source: '{{ onion_service_container_name }}_data'
  13. target: /var/lib/tor
  14. read_only: false
  15. - type: volume
  16. source: '{{ onion_service_container_name }}_key'
  17. target: /onion-service
  18. read_only: false
  19. - type: tmpfs
  20. target: /tmp # torrc
  21. # nosuid,nodev,noexec added by default
  22. tmpfs_mode: '1777'
  23. tmpfs_size: 4k
  24. networks: [name: '{{ onion_service_network_name }}']
  25. purge_networks: yes
  26. cap_drop: [ALL]
  27. security_opts: [no-new-privileges]
  28. cpu_quota: 8000
  29. cpu_period: 10000
  30. memory: 128M
  31. restart_policy: unless-stopped
  32. healthcheck: "{{ {'test': ['NONE']} if onion_service_disable_healthcheck else omit }}"
  33. state: '{{ onion_service_container_state }}'
  34. register: _container
  35. - name: wait for onion service address
  36. wait_for:
  37. path: "{{ (_container.container.Mounts | items2dict(key_name='Destination', value_name='Source'))['/onion-service'] }}/hostname"
  38. register: _address_file
  39. when: _container.container.State.Running | default(False)
  40. - name: read onion service address
  41. slurp:
  42. src: '{{ _address_file.path }}'
  43. register: _address_base64
  44. when: not (_address_file.skipped | default(False))
  45. - name: decode onion service address
  46. set_fact:
  47. onion_service_address: '{{ _address_base64.content | b64decode | trim }}'
  48. when: not (_address_base64.skipped | default(False))