Skip to content

Commit

Permalink
Merge pull request #150 from Temelio/develop
Browse files Browse the repository at this point in the history
Add logrotate configuration
  • Loading branch information
lmachetel authored May 15, 2019
2 parents 7913c8b + 1fc6a63 commit 1854303
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
19 changes: 15 additions & 4 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: 'Delete default configuration files'
- name: 'CONFIGURE | Delete default configuration files'
file:
path: "{{ item }}"
state: 'absent'
Expand All @@ -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 }}"
Expand All @@ -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 }}"
Expand All @@ -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
21 changes: 21 additions & 0 deletions templates/logrotate.j2
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1854303

Please sign in to comment.