initial commit

This commit is contained in:
Ludovic Cartier
2024-12-17 17:20:50 +01:00
parent a24d032a03
commit 4c65e9c8b4
17 changed files with 315 additions and 2 deletions

34
tasks/configure.yml Normal file
View File

@ -0,0 +1,34 @@
---
- name: 'nginx | push configuration'
copy:
src: '{{ item }}'
dest: /etc/nginx/conf.d/
owner: root
mode: 600
with_fileglob:
- conf.d/*
notify:
- 'nginx restart'
tags:
- nginx
- nginx_configure
- name: 'nginx | push custom configuration'
copy:
src: '{{ item }}'
dest: /etc/nginx/conf.d/custom/
owner: root
mode: 600
with_fileglob:
- conf.d/custom/*
notify:
- 'nginx restart'
tags:
- nginx
- nginx_configure
#- name: 'nginx | disable general gzip'
# replace:
# path: /etc/nginx/nginx.conf
# regexp: 'gzip on;'
# replace: 'gzip off;'

30
tasks/install.yml Normal file
View File

@ -0,0 +1,30 @@
---
- name: "nginx | apt update cache"
apt:
update_cache: yes
cache_valid_time: 86400 #One day
tags:
- nginx
- nginx_install
- name: "nginx | install packages"
apt:
name: "{{ item }}"
update_cache: true
state: present
with_items:
- nginx-common
- nginx-full
register: is_nginx
tags:
- nginx
- nginx_install
- name: "nginx | remove default vhost"
file:
path: "/etc/nginx/sites-enabled/default"
state: absent
tags:
- nginx
- nginx_install

12
tasks/main.yml Normal file
View File

@ -0,0 +1,12 @@
---
- name: "nginx | installation"
include: install.yml
- name: "nginx | custom configuration"
include: configure.yml
- name: "nginx | status page"
include: status.yml
- name: "nginx | configure vhost"
include: vhost.yml

15
tasks/status.yml Normal file
View File

@ -0,0 +1,15 @@
---
- name: "nginx | copy status vhost"
copy:
src: "status.conf"
dest: "/etc/nginx/sites-available/00-status.conf"
mode: "0644"
force: yes
backup: yes
when: is_nginx
- name: "nginx | activate the status vhost"
file:
src: "/etc/nginx/sites-available/00-status.conf"
dest: "/etc/nginx/sites-enabled/00-status.conf"
state: link

66
tasks/vhost.yml Normal file
View File

@ -0,0 +1,66 @@
---
- name: 'nginx | configure vhosts'
template:
src: "{{ item.value.template | default('vhost.conf.j2') }}"
dest: "/etc/nginx/sites-available/{{ item.key }}.conf"
owner: root
group: root
mode: 0644
loop: "{{ nginx_vhosts | dict2items }}"
notify:
- nginx reload
tags:
- nginx
- nginx_vhost
- name: 'nginx | enable vhosts'
file:
src: "/etc/nginx/sites-available/{{ item.key }}.conf"
dest: "/etc/nginx/sites-enabled/{%if item.value.priority is defined%}{{ item.value.priority }}-{%endif%}{{ item.key }}.conf"
state: link
loop: "{{ nginx_vhosts | dict2items }}"
when: item.value.enabled is not defined or item.value.enabled
notify:
- nginx reload
tags:
- nginx
- nginx_vhost
- name: 'nginx | configure DocumentRoot'
file:
path: "{{ item.value.documentroot.path | default(nginx_documentroot_default) }}"
state: directory
owner: "{{ item.value.documentroot.user | default(nginx_user) }}"
group: "{{ item.value.documentroot.group | default(nginx_group) }}"
loop: "{{ nginx_vhosts | dict2items }}"
loop_control:
label: "{{ item.value.documentroot | default([]) }}"
when:
- item.value.enabled is undefined or item.value.enabled
- item.value.documentroot is defined
- item.value.documentroot != False
notify:
- nginx reload
tags:
- nginx
- nginx_vhost
- name: 'nginx | configure nginx logs'
file:
path: "/var/log/nginx/{{ item.value.servername }}"
state: directory
owner: root
group: adm
loop: "{{ nginx_vhosts | dict2items }}"
loop_control:
label: "{{ item.value.servername | default([]) }}"
when:
- item.value.enabled is undefined or item.value.enabled
- item.value.documentroot is defined
- item.value.documentroot != False
notify:
- nginx reload
tags:
- nginx
- nginx_vhost