ansible-role-apache/tasks/apache-basic-auth.yml

31 lines
1.4 KiB
YAML

---
- name: Apache auth modules on Debian or Ubuntu
block:
- name: Load the basic auth modules
apache2_module: name={{ item }} state=present
with_items: '{{ apache_basic_auth_modules }}'
notify: apache2 reload
- name: Install the python-passlib library
apt: pkg=python-passlib state=present
when: ansible_distribution_file_variety == "Debian"
tags: [ 'apache', 'apache_basic_auth' ]
- name: Create the authentication directory
file: path={{ apache_basic_auth_dir }} mode=0750 owner=root group={{ apache_group }} state=directory
tags: [ 'apache', 'apache_basic_auth' ]
- name: Create the basic auth file when it is unique to all the virtualhosts
htpasswd: path={{ apache_basic_auth_file }} name={{ item.username }} password={{ item.password }} create=yes state={{ item.state }} owner=root group={{ apache_group }} mode=0640
when: apache_basic_users is defined and apache_basic_auth_single_file
with_items: '{{ apache_basic_users }}'
tags: [ 'apache', 'apache_basic_auth' ]
- name: Create the basic auth files
htpasswd: path={{ item.auth_file }} name={{ item.username }} password={{ item.password }} create=yes state={{ item.state }} owner=root group={{ apache_group }} mode=0640
with_items: '{{ apache_basic_users | default([]) }}'
when: apache_basic_users is defined and not apache_basic_auth_single_file
tags: [ 'apache', 'apache_basic_auth' ]