infra/roles/nginx-websites/tasks/nginx-websites.yml

61 lines
1.5 KiB
YAML

---
- name: create directories for static websites
file:
state: directory
owner: "{{ item.owner | default('www-data') }}"
group: www-data
mode: 0755
path: "/var/www/{{ item.name }}"
when:
- item.root_dir is not defined
loop_control:
label: "{{ item.name }}"
with_items: "{{ static_sites }}"
- name: symlink wwwsudois shared because nginx needs relative paths
file:
state: link
src: "/var/www/shared"
dest: "/var/www/{{ item.name }}/.shared"
mode: 0755
when:
- item.name != "www.sudo.is"
- item.custom_autoindex|default(True)
- item.root_dir is not defined
with_items: "{{ static_sites }}"
loop_control:
label: "{{ item.name }}"
- name: no symlink if no custom autoindex
file:
state: absent
dest: "/var/www/{{ item.name }}/.shared"
when:
- item.name != "www.sudo.is"
- item.custom_autoindex|default(True) != True
- item.root_dir is not defined
with_items: "{{ static_sites }}"
loop_control:
label: "{{ item.name }}"
- name: template robots.txt
template:
src: robots.txt.j2
dest: "/var/www/{{ item.name }}/robots.txt"
owner: "{{ myusername }}"
group: www-data
mode: 0644
with_items: "{{ static_sites }}"
when:
- item.robots | default(false)
- name: template static website configs
template:
src: nginx-static-vhost.j2
dest: /etc/nginx/sites-enabled/02-{{ item.name }}
owner: www-data
group: www-data
with_items: "{{ static_sites }}"
notify: reload nginx