First public version

master
Oleg Vasilev 2021-06-03 16:51:46 +03:00
parent 78569d4ca2
commit bf0fe49b4b
5 changed files with 119 additions and 2 deletions

View File

@ -1,3 +1,5 @@
# nginx # Nginx ansible role
Simple template-based (no lengthy configuration vars) role.
Ansible role for nginx ### Variables
See `defaults/main.yml`

4
defaults/main.yml Normal file
View File

@ -0,0 +1,4 @@
---
# List of configs to deploy from <templates_dir>/nginx/vhosts
nginx_vhosts: []

11
handlers/main.yml Normal file
View File

@ -0,0 +1,11 @@
---
- name: nginx | Check new config
shell: nginx -t
listen: nginx | Config changed
- name: nginx | Reload
systemd:
name: nginx
state: reloaded
listen: nginx | Config changed

64
tasks/main.yml Normal file
View File

@ -0,0 +1,64 @@
---
- name: nginx | Install packages
pacman:
name:
- nginx-mainline
- mailcap
state: present
update_cache: yes
- name: nginx | Remove stupid apache-style dirs
file:
path: "{{ item }}"
state: absent
with_items:
- /etc/nginx/sites-available
- /etc/nginx/sites-enabled
- name: nginx | Add vhosts directory
file:
path: /etc/nginx/vhosts
state: directory
mode: 0700
owner: root
group: root
- name: nginx | Deploy main config
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
mode: 0600
owner: root
group: root
notify: nginx | Config changed
- name: nginx | Deploy vhosts configs
template:
src: nginx/vhosts/{{ item }}
dest: /etc/nginx/vhosts/{{ item }}
mode: 0600
owner: root
group: root
with_items: "{{ nginx_vhosts }}"
notify: nginx | Config changed
- name: nginx | Get file list in config dir
find:
path: /etc/nginx/vhosts
hidden: yes
register: nginx_vhosts_find
- name: nginx | Remove unmanaged shit
file:
path: "/etc/nginx/vhosts/{{ item.path | basename }}"
state: absent
with_items:
- "{{ nginx_vhosts_find.files }}"
when: (item.path | basename) not in nginx_vhosts
- name: nginx | Enable and start nginx
systemd:
name: nginx
enabled: yes
state: started

36
templates/nginx.conf.j2 Normal file
View File

@ -0,0 +1,36 @@
# {{ ansible_managed }}
user http;
worker_processes auto;
error_log /var/log/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
# Specified in systemd unit file
#pid /run/nginx.pid;
events {
worker_connections 512;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
types_hash_bucket_size 128;
client_max_body_size 512m;
include vhosts/*.conf;
}