Matrix Docker Ansible eploy
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 

61 Zeilen
3.4 KiB

  1. ---
  2. # When we're dealing with raw htpasswd content, we just store it in the file directly.
  3. - name: Ensure matrix-metrics-htpasswd is present when generated from raw content (protecting /metrics/* URIs)
  4. ansible.builtin.copy:
  5. content: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content }}"
  6. dest: "{{ matrix_nginx_proxy_data_path }}/matrix-metrics-htpasswd"
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_groupname }}"
  9. mode: 0600
  10. when: not matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username
  11. # Alternatively, we need to use the `htpasswd` tool to generate the htpasswd file.
  12. # There's an Ansible module that helps with that, but it requires passlib (a Python module) to be installed on the server.
  13. # See: https://docs.ansible.com/ansible/2.3/htpasswd_module.html#requirements-on-host-that-executes-module
  14. # We support various distros, with various versions of Python. Installing additional Python modules can be a hassle.
  15. # As a workaround, we run `htpasswd` from an Apache container image.
  16. - block:
  17. - name: Ensure Apache Docker image is pulled for generating matrix-metrics-htpasswd from username/password (protecting /metrics/* URIs)
  18. docker_image:
  19. name: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image }}"
  20. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  21. force_source: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  22. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_force_pull }}"
  23. register: result
  24. retries: "{{ matrix_container_retries_count }}"
  25. delay: "{{ matrix_container_retries_delay }}"
  26. until: result is not failed
  27. # We store the password in a file and make the `htpasswd` tool read it from there,
  28. # as opposed to passing it directly on stdin (which will expose it to other processes on the server).
  29. - name: Store metrics password in a temporary file
  30. ansible.builtin.copy:
  31. content: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password }}"
  32. dest: "/tmp/matrix-nginx-proxy-metrics-password"
  33. mode: 0400
  34. owner: "{{ matrix_user_uid }}"
  35. group: "{{ matrix_user_gid }}"
  36. - name: Generate matrix-metrics-htpasswd from username/password (protecting /metrics/* URIs)
  37. ansible.builtin.command:
  38. cmd: >-
  39. {{ matrix_host_command_docker }} run
  40. --rm
  41. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  42. --cap-drop=ALL
  43. --network=none
  44. --mount type=bind,src={{ matrix_nginx_proxy_data_path }},dst=/data
  45. --mount type=bind,src=/tmp/matrix-nginx-proxy-metrics-password,dst=/password,ro
  46. --entrypoint=/bin/sh
  47. {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image }}
  48. -c
  49. 'cat /password | htpasswd -i -c /data/matrix-metrics-htpasswd {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username }} && chmod 600 /data/matrix-metrics-htpasswd'
  50. changed_when: true
  51. - name: Delete temporary metrics password file
  52. ansible.builtin.file:
  53. path: /tmp/matrix-nginx-proxy-metrics-password
  54. state: absent
  55. when: matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username != ''