diff --git a/.travis.yml b/.travis.yml index 25354a7..1c146f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,24 +3,15 @@ language: python services: docker env: - global: - - ROLE_NAME: logrotate matrix: + - MOLECULE_DISTRO: centos8 - MOLECULE_DISTRO: centos7 - - MOLECULE_DISTRO: centos6 + - MOLECULE_DISTRO: ubuntu2004 - MOLECULE_DISTRO: ubuntu1804 - - MOLECULE_DISTRO: debian9 - MOLECULE_DISTRO: debian10 install: - - pip install molecule docker - - - git clone https://github.com/arillso/tests molecule/default/lint - -before_script: - - cd ../ - - mv ansible.$ROLE_NAME arillso.$ROLE_NAME - - cd arillso.$ROLE_NAME + - pip install molecule yamllint ansible-lint docker script: - molecule test diff --git a/CHANGELOG.md b/CHANGELOG.md index a1923a3..2893dca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,27 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [human-readable changelog](https://keepachangelog.com/en/1.0.0/). +## 1.6.0 + +### Fixed + +- Travis CI and molecule setup. +- The src option requires state to be 'link' or 'hard' (breaking in Ansible + 2.10) (Fixes: #14). + +### Changed + +- `logrotate_use_hourly_rotation` will no longer clean the symlink in + `cron.daily`. +- Bumped tested distros versions. + +### Added + +- Options to enable or not wtmp/btmp config by [smutel](https://github.com/smutel) + via PR #25 (Fixes: #23). +- Option to skip global configuration file by [fhsctv](https://github.com/fhsctv) + via PR #28. + ## 1.5.2 ### Fixed diff --git a/README.md b/README.md index cb78a36..1b5698e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ## Description -Installs and configures logrotate +Installs and configures logrotate. ## Installation @@ -14,11 +14,11 @@ Installs and configures logrotate ## Requirements -None +None. ## Role Variables -### imclude files +### include files Path to the imclude files. @@ -26,9 +26,17 @@ Path to the imclude files. logrotate_include_dir: /etc/logrotate.d ``` +### logrotate_global_config + +Enable/disable global configuration of `/etc/logrotate.conf`. + +```yml +logrotate_global_config: true +``` + ### logrotate_use_hourly_rotation -Enable hourly rotation with cron. +Enable/disable hourly rotation with cron. ```yml logrotate_use_hourly_rotation: false @@ -49,7 +57,7 @@ logrotate_options: ### Package -package name to install logrotate. +Package name to install `logrotate`. ```yml logrotate_package: logrotate @@ -57,9 +65,10 @@ logrotate_package: logrotate ### default config -logroate for wtmp +Logrotate for `wtmp`: ```yml +logrotate_wtmp_enable: true logrotate_wtmp: logs: - /var/log/wtmp @@ -70,9 +79,10 @@ logrotate_wtmp: - rotate 1 ``` -logroate for btmp +Logrotate for `btmp`: ```yml +logrotate_btmp_enable: true logrotate_btmp: logs: - /var/log/btmp @@ -83,7 +93,7 @@ logrotate_btmp: - rotate 1 ``` -### applications config +### Applications config More log files can be added that will logorate. diff --git a/defaults/main.yml b/defaults/main.yml index ceebd98..5d895f6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,6 +1,4 @@ --- -# defaults file for arillso.logrotate - # List of global options. If this is empty the default options of the # distribution are used. logrotate_options: [] @@ -8,13 +6,17 @@ logrotate_options: [] # Path to the imclude files logrotate_include_dir: /etc/logrotate.d -# package name to install logrotate. +# Package name to install logrotate. logrotate_package: logrotate +# Enable global configuration handling +logrotate_global_config: true + # Enable hourly rotation with cron. logrotate_use_hourly_rotation: false -# logroate for wtmp +# Logrotate for wtmp +logrotate_wtmp_enable: true logrotate_wtmp: logs: - /var/log/wtmp @@ -24,7 +26,8 @@ logrotate_wtmp: - create 0664 root utmp - rotate 1 -# logroate for btmp +# Logrotate for btmp +logrotate_btmp_enable: true logrotate_btmp: logs: - /var/log/btmp diff --git a/handlers/main.yml b/handlers/main.yml deleted file mode 100644 index 7d6e65e..0000000 --- a/handlers/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# handlers file for arillso.logrotate diff --git a/meta/main.yml b/meta/main.yml index 3655d44..08e68db 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,5 +1,8 @@ --- +dependencies: [] + galaxy_info: + role_name: unbound author: 'arillso' description: 'Ansible role for installs and configures logratet on Linux' license: MIT @@ -7,20 +10,17 @@ galaxy_info: platforms: - name: EL versions: - - 6 - 7 + - 8 - name: Fedora versions: - - 29 + - 32 - name: Ubuntu versions: - bionic - - cosmic - - disco + - focal - name: Debian versions: - - jessie - - stretch - buster galaxy_tags: diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..c3085cf --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,12 @@ +--- +- name: Converge + hosts: all + + pre_tasks: + - name: update apt cache + apt: update_cache=yes cache_valid_time=600 + when: ansible_distribution == 'Ubuntu' + changed_when: false + + roles: + - role: ansible.logrotate diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index c80c5c6..abbef35 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -3,11 +3,9 @@ dependency: name: galaxy driver: name: docker -lint: - name: yamllint platforms: - name: instance - image: 'geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest' + image: geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro @@ -15,13 +13,11 @@ platforms: pre_build_image: true provisioner: name: ansible - lint: - name: ansible-lint playbooks: - converge: ${MOLECULE_PLAYBOOK:-playbook.yml} + converge: ${MOLECULE_PLAYBOOK:-converge.yml} scenario: name: default -verifier: - name: testinfra - lint: - name: flake8 +lint: | + set -e + yamllint . + ansible-lint diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml deleted file mode 100644 index 5a53eaf..0000000 --- a/molecule/default/playbook.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- name: Converge - hosts: all - roles: - - role: arillso.logrotate diff --git a/tasks/main.yml b/tasks/main.yml index 4119297..c0a8ec0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,6 +1,4 @@ --- -# tasks file for arillso.logrotate - - name: add OS specific variables include_vars: '{{ loop_vars }}' with_first_found: @@ -23,7 +21,7 @@ - configuration - packages -- name: 'install logrotate packages' +- name: install logrotate packages become: true package: name: '{{ logrotate_package }}' @@ -34,7 +32,7 @@ tags: - packages -- name: 'create logrotate configuration file' +- name: create logrotate configuration file become: true template: src: 'etc/logrotate.conf.j2' @@ -44,8 +42,9 @@ mode: 0644 tags: - configuration + when: logrotate_global_config | bool -- name: 'create logrotate application configuration files' +- name: create logrotate application configuration files become: true template: src: 'etc/logrotate.d/application.j2' @@ -58,8 +57,10 @@ tags: - configuration -- name: Symlink for hourly rotation +- name: symlink for hourly rotation file: - path: "/etc/cron.hourly/logrotate" - src: "/etc/cron.daily/logrotate" - state: "{{ 'link' if logrotate_use_hourly_rotation else 'absent' }}" + path: '/etc/cron.hourly/logrotate' + src: '/etc/cron.daily/logrotate' + mode: 0644 + state: link + when: logrotate_use_hourly_rotation | bool diff --git a/templates/etc/logrotate.conf.j2 b/templates/etc/logrotate.conf.j2 index 487181c..47d50a1 100644 --- a/templates/etc/logrotate.conf.j2 +++ b/templates/etc/logrotate.conf.j2 @@ -15,16 +15,20 @@ include {{ logrotate_include_dir }} # no packages own wtmp, or btmp -- we'll rotate them here +{% if logrotate_wtmp_enable %} {{ logrotate_wtmp.logs | join(" ") }} { {% for option in logrotate_wtmp.options %} {{ option }} {% endfor %} } +{% endif %} +{% if logrotate_btmp_enable %} {{ logrotate_btmp.logs | join(" ") }} { {% for option in logrotate_btmp.options %} {{ option }} {% endfor %} } +{% endif %} # system-specific logs may be configured here diff --git a/vars/CentOS.yml b/vars/CentOS.yml index 84412dc..b3da9e5 100644 --- a/vars/CentOS.yml +++ b/vars/CentOS.yml @@ -1,7 +1,4 @@ --- -# vars file for arillso.logrotate - -# List of global options for the different systems. logrotate_distribution_options: - weekly - rotate 4 diff --git a/vars/Debian.yml b/vars/Debian.yml index 84412dc..b3da9e5 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -1,7 +1,4 @@ --- -# vars file for arillso.logrotate - -# List of global options for the different systems. logrotate_distribution_options: - weekly - rotate 4 diff --git a/vars/RedHat.yml b/vars/RedHat.yml index 84412dc..b3da9e5 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -1,7 +1,4 @@ --- -# vars file for arillso.logrotate - -# List of global options for the different systems. logrotate_distribution_options: - weekly - rotate 4 diff --git a/vars/Ubuntu.yml b/vars/Ubuntu.yml index 679b0f0..fdd6629 100644 --- a/vars/Ubuntu.yml +++ b/vars/Ubuntu.yml @@ -1,7 +1,4 @@ --- -# vars file for arillso.logrotate - -# List of global options for the different systems. logrotate_distribution_options: - weekly - rotate 4 diff --git a/vars/defaults.yml b/vars/defaults.yml deleted file mode 100644 index 037a804..0000000 --- a/vars/defaults.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for arillso.logrotate