diff --git a/README.md b/README.md index 8c0520d..fd31253 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,12 @@ nginx_conf: nginx_servers: [] nginx_upstreams: [] + +nginx_log_path: '/var/log/nginx' +default_nginx_logrotate_config_modify: True +nginx_logrotate_config: + - dest: '/etc/logrotate.d/nginx' +nginx_logrotate_rotate: '54' ``` ## Configure servers diff --git a/defaults/main.yml b/defaults/main.yml index f120e58..8ada690 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -77,3 +77,9 @@ nginx_conf: nginx_maps: [] nginx_servers: [] nginx_upstreams: [] + +nginx_log_path: '/var/log/nginx' +default_nginx_logrotate_config_modify: True +nginx_logrotate_config: + - dest: '/etc/logrotate.d/nginx' +nginx_logrotate_rotate: '54' diff --git a/requirements.txt b/requirements.txt index 914b5d0..56343f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ docker==3.7.2 molecule==2.20.1 -pytest==4.4.0 +pytest==4.5.0 six==1.11.0 -tox==3.8.6 +tox==3.10.0 testinfra==1.19.0 diff --git a/tasks/configure.yml b/tasks/configure.yml index b0e17c5..32bc548 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,6 +1,6 @@ --- -- name: 'Delete default configuration files' +- name: 'CONFIGURE | Delete default configuration files' file: path: "{{ item }}" state: 'absent' @@ -9,7 +9,7 @@ when: "nginx_delete_default_config_files" -- name: 'Create server configuration folders' +- name: 'CONFIGURE | Create server configuration folders' file: path: "{{ item }}" owner: "{{ nginx_config_permissions.folders.owner }}" @@ -21,7 +21,7 @@ - "{{ nginx_config_paths.folders.sites_enabled }}" -- name: 'Manage main configuration file' +- name: 'CONFIGURE | Manage main configuration file' template: src: "{{ role_path }}/templates/nginx.conf.j2" dest: "{{ nginx_config_paths.files.main }}" @@ -31,6 +31,17 @@ notify: 'HANDLER | Restart Nginx' -- name: 'Manage items configuration' +- name: 'CONFIGURE | Manage items configuration' include_tasks: "{{ role_path }}/tasks/configure_items.yml" notify: 'HANDLER | Restart Nginx' + + +- name: 'CONFIGURE | manage logorotate' + template: + src: "{{ role_path }}/templates/logrotate.j2" + dest: "{{ item.dest }}" + owner: "{{ item.owner | default('root') }}" + group: "{{ item.group | default('root') }}" + mode: "{{ item.mode | default (0644) }}" + with_items: "{{ nginx_logrotate_config }}" + when: default_nginx_logrotate_config_modify diff --git a/templates/logrotate.j2 b/templates/logrotate.j2 new file mode 100644 index 0000000..ae496b5 --- /dev/null +++ b/templates/logrotate.j2 @@ -0,0 +1,21 @@ +{{ ansible_managed | comment }} + +# Logrotate configuration +#============================================================================== + +# Nginx log +{{ nginx_log_path }}/*.log" { + {{ nginx_logrotate_daily | default('daily') }} + {{ nginx_logrotate_missing | default('missingok') }} + {{ nginx_logrotate_rotate | default(' 54') }} + {{ nginx_logrotate_compress | default('compress') }} + {{ nginx_logrotate_delaycompress | default('delaycompress') }} + {{ nginx_logrotate_notify | default('notifempty') }} + {{ nginx_logrotate_create | default('create 640 nginx adm') }} + {{ nginx_logrotate_sharedscripts | default('sharedscripts') }} + postrotate + if [ -f /var/run/nginx.pid ]; then + kill -USR1 `cat /var/run/nginx.pid` + fi + endscript +}