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.
 
 

56 Zeilen
3.2 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. 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. # We store the password in a file and make the `htpasswd` tool read it from there,
  24. # as opposed to passing it directly on stdin (which will expose it to other processes on the server).
  25. - name: Store metrics password in a temporary file
  26. copy:
  27. content: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password }}"
  28. dest: "/tmp/matrix-nginx-proxy-metrics-password"
  29. mode: 0400
  30. owner: "{{ matrix_user_uid }}"
  31. group: "{{ matrix_user_gid }}"
  32. - name: Generate matrix-metrics-htpasswd from username/password (protecting /metrics/* URIs)
  33. command:
  34. cmd: >-
  35. {{ matrix_host_command_docker }} run
  36. --rm
  37. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  38. --cap-drop=ALL
  39. --network=none
  40. --mount type=bind,src={{ matrix_nginx_proxy_data_path }},dst=/data
  41. --mount type=bind,src=/tmp/matrix-nginx-proxy-metrics-password,dst=/password,ro
  42. --entrypoint=/bin/sh
  43. {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image }}
  44. -c
  45. 'cat /password | htpasswd -i -c /data/matrix-metrics-htpasswd {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username }} && chmod 600 /data/matrix-metrics-htpasswd'
  46. - name: Delete temporary metrics password file
  47. file:
  48. path: /tmp/matrix-nginx-proxy-metrics-password
  49. state: absent
  50. when: matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username != ''