From 077fa05d5ef4bc97a4bb098a73e3cb2eea62e027 Mon Sep 17 00:00:00 2001 From: Joshua Ford Date: Sat, 6 Mar 2021 16:12:11 -0600 Subject: [PATCH] Initial commit --- .ansible-lint | 7 ++ .gitignore.io | 160 ++++++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 6 ++ .yamllint | 33 +++++++++ LICENSE | 30 ++++++++ README.md | 36 +++++++++ defaults/main.yml | 5 ++ files/logrotate.conf | 22 ++++++ handlers/main.yml | 1 + meta/main.yml | 16 ++++ requirements.txt | 4 + tasks/config.yml | 8 ++ tasks/install.yml | 11 +++ tasks/main.yml | 4 + tasks/service.yml | 6 ++ tests/inventory | 2 + tests/test.yml | 5 ++ vars/main.yml | 2 + 18 files changed, 358 insertions(+) create mode 100644 .ansible-lint create mode 100644 .gitignore.io create mode 100644 .pre-commit-config.yaml create mode 100644 .yamllint create mode 100644 LICENSE create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 files/logrotate.conf create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 requirements.txt create mode 100644 tasks/config.yml create mode 100644 tasks/install.yml create mode 100644 tasks/main.yml create mode 100644 tasks/service.yml create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 vars/main.yml diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..aff0c71 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,7 @@ +exclude_paths: + - ./venv +skip_list: + - '106' # Role name {} does not match ``^[a-z][a-z0-9_]+$`` pattern +use_default_rules: true +verbosity: 1 + diff --git a/.gitignore.io b/.gitignore.io new file mode 100644 index 0000000..d5945c2 --- /dev/null +++ b/.gitignore.io @@ -0,0 +1,160 @@ +# Created by https://www.toptal.com/developers/gitignore/api/python,ansible,virtualenv +# Edit at https://www.toptal.com/developers/gitignore?templates=python,ansible,virtualenv + +### Ansible ### +*.retry + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# profiling data +.prof + +### VirtualEnv ### +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +pip-selfcheck.json + +# End of https://www.toptal.com/developers/gitignore/api/python,ansible,virtualenv + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..2704a1a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/ansible-community/ansible-lint.git + rev: v4.3.7 + hooks: + - id: ansible-lint + files: \.(yaml|yml)$ diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..8827676 --- /dev/null +++ b/.yamllint @@ -0,0 +1,33 @@ +--- +# Based on ansible-lint config +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + colons: + max-spaces-after: -1 + level: error + commas: + max-spaces-after: -1 + level: error + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + max: 3 + level: error + hyphens: + level: error + indentation: disable + key-duplicates: enable + line-length: disable + new-line-at-end-of-file: disable + new-lines: + type: unix + trailing-spaces: disable + truthy: disable diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5ccd8fc --- /dev/null +++ b/LICENSE @@ -0,0 +1,30 @@ +BSD 3-Clause License + +Copyright (c) 2021, Joshua Ford +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..ebabf5a --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/H2H43P9OI) + +Ansible role: logrotate +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +See [LICENSE](LICENSE). + diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e9e3512 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,5 @@ +--- +# State of the logrotate package. Use `present` to make sure the package is +# installed, or use `latest` to make sure the package is always at the latest +# version. +logrotate_package_state: present diff --git a/files/logrotate.conf b/files/logrotate.conf new file mode 100644 index 0000000..c28ec0c --- /dev/null +++ b/files/logrotate.conf @@ -0,0 +1,22 @@ +# This file is managed by Ansbile. + +# see "man logrotate" for details +# rotate log files weekly +weekly + +# keep 4 weeks worth of backlogs +rotate 4 + +# create new (empty) log files after rotating old ones +create + +# use date as a suffix of the rotated file +#dateext + +# uncomment this if you want your log files compressed +#compress + +# packages drop log rotation information into this directory +include /etc/logrotate.d + +# system-specific logs may be also be configured here. diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..9123602 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,16 @@ +galaxy_info: + role_name: logrotate + author: stonesoupkitchen + description: Configure logrotate on Linux systems. + license: BSD-3-Clause + min_ansible_version: 2.9 + platforms: + - name: Debian + versions: + - buster + galaxy_tags: + - logrotate + - logging + - logs +dependencies: [] + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..0d79003 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ansible >= 2.9 +ansible-lint +pre-commit >= 2.0.0, < 3.0.0 +molecule-docker diff --git a/tasks/config.yml b/tasks/config.yml new file mode 100644 index 0000000..4094f21 --- /dev/null +++ b/tasks/config.yml @@ -0,0 +1,8 @@ +--- +- name: Configure /etc/logrotate.conf + copy: + src: logrotate.conf + dest: /etc/logrotate.conf + owner: root + group: root + mode: '0644' diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..98f80cb --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,11 @@ +# Install the logrotate package. +--- +- name: Define logrotate_package + set_fact: + logrotate_package: "{{ __logrotate_package }}" + when: logrotate_package is not defined + +- name: Install logrotate + apt: + name: "{{ logrotate_package }}" + state: "{{ logrotate_package_state }}" diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..0cd8666 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- include_tasks: "install.yml" +- include_tasks: "config.yml" +- include_tasks: "service.yml" diff --git a/tasks/service.yml b/tasks/service.yml new file mode 100644 index 0000000..1bc4f04 --- /dev/null +++ b/tasks/service.yml @@ -0,0 +1,6 @@ +--- +- name: Enable logrotate + service: + name: logrotate + enabled: yes + diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..d309a47 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - logrotate \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..2c48b2b --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +__logrotate_package: "logrotate"