Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

61 строка
3.5 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. - when: matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username != ''
  17. block:
  18. - name: Ensure Apache Docker image is pulled for generating matrix-metrics-htpasswd from username/password (protecting /metrics/* URIs)
  19. community.docker.docker_image:
  20. name: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image }}"
  21. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  22. 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 }}"
  23. 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 }}"
  24. register: result
  25. retries: "{{ devture_playbook_help_container_retries_count }}"
  26. delay: "{{ devture_playbook_help_container_retries_delay }}"
  27. until: result is not failed
  28. # We store the password in a file and make the `htpasswd` tool read it from there,
  29. # as opposed to passing it directly on stdin (which will expose it to other processes on the server).
  30. - name: Store metrics password in a temporary file
  31. ansible.builtin.copy:
  32. content: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password }}"
  33. dest: "/tmp/matrix-nginx-proxy-metrics-password"
  34. mode: 0400
  35. owner: "{{ matrix_user_uid }}"
  36. group: "{{ matrix_user_gid }}"
  37. - name: Generate matrix-metrics-htpasswd from username/password (protecting /metrics/* URIs)
  38. ansible.builtin.command:
  39. cmd: >-
  40. {{ devture_systemd_docker_base_host_command_docker }} run
  41. --rm
  42. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  43. --cap-drop=ALL
  44. --network=none
  45. --mount type=bind,src={{ matrix_nginx_proxy_data_path }},dst=/data
  46. --mount type=bind,src=/tmp/matrix-nginx-proxy-metrics-password,dst=/password,ro
  47. --entrypoint=/bin/sh
  48. {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image }}
  49. -c
  50. 'cat /password | htpasswd -i -c /data/matrix-metrics-htpasswd {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username }} && chmod 600 /data/matrix-metrics-htpasswd'
  51. changed_when: true
  52. - name: Delete temporary metrics password file
  53. ansible.builtin.file:
  54. path: /tmp/matrix-nginx-proxy-metrics-password
  55. state: absent