--- - name: "Create empty htpswd file" file: path: "{{ htpasswd_file_path }}" state: touch - name: "Install latest passlib with pip" pip: name=passlib - name: "Add a user and password to empty htpswd file" community.general.htpasswd: path: "{{ htpasswd_file_path }}" name: "{{ basic_auth_username }}" password: "{{ basic_auth_password }}" - name: "Read credentials out of htpasswd file" ansible.builtin.slurp: src: "{{ htpasswd_file_path }}" register: credentials - name: "Create prometheus secrets" become: yes kubernetes.core.k8s: definition: api_version: v1 kind: Secret metadata: namespace: "{{ namespace }}" name: "{{ basic_auth_secret_name }}" type: Opaque data: auth: "{{ credentials['content'] }}" - name: "Delete htpasswd file" become: yes file: path: "{{ htpasswd_file_path }}" state: absent