sce/roles/nginx/tasks/main.yml

38 lines
987 B
YAML

---
- name: Install nginx
ansible.builtin.apt:
name: nginx
# Debian-ism to prevent auto-start of nginx on installation as
# we still need to do some configuration.
policy_rc_d: 101
- name: Install passlib (for htpasswd)
ansible.builtin.apt:
name: python3-passlib
- name: Create password file for HTTP basic authentication
community.general.htpasswd:
path: /etc/nginx/passwdfile
name: admin
password: "{{ nginx_htpasswd }}"
owner: root
group: www-data
mode: "0640"
when: nginx_htpasswd is defined
- name: Check if the passwdfile exists
ansible.builtin.stat:
path: /etc/nginx/passwdfile
register: htpasswdfile
- name: Iterate over configured nginx sites
ansible.builtin.include_tasks: site.yml
loop: "{{ nginx_sites }}"
vars:
site_name: "{{ item['name'] }}"
site_port: "{{ item['port'] }}"
- name: Disable default nginx site
ansible.builtin.file:
path: /etc/nginx/sites-enabled/default
state: absent