--- - name: "Create empty htpswd file" ansible.builtin.file: path: "{{ htpasswd_file_path }}" state: touch mode: '0600' - 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 }}" mode: '0600' - name: "Read credentials out of htpasswd file" ansible.builtin.slurp: src: "{{ htpasswd_file_path }}" register: "credentials" - name: "Delete htpasswd file" ansible.builtin.file: path: "{{ htpasswd_file_path }}" state: absent - name: "Setting htpasswd to <{{ credentials_name }}>" ## noqa var-naming ansible.builtin.set_fact: "{{ credentials_name }}={{ credentials.content | b64decode | trim | replace('$','$$') }}"