--- - name: create authentication directory file: state: directory path: /etc/nginx/auth/ owner: root group: www-data mode: 0750 - name: generate user entries copy: dest: "/etc/nginx/auth/{{ nginx_auth_basic_filename }}.htpasswd" owner: root group: www-data mode: 0640 content: | {% for user,password in nginx_auth_basic_users.items() %} {{ user }}:{{ password | password_hash('apr_md5_crypt', (user~'@'~inventory_hostname~'/nginx') | apr_md5_crypt_salt) }} {% endfor %}