From feaa54986d876d637ae15d25709c3a25a44f6fe5 Mon Sep 17 00:00:00 2001 From: Nemo Date: Sun, 12 Jul 2020 10:14:25 +0200 Subject: [PATCH] Update munin-node role and keep it locally --- group_vars/all/all.yml | 3 - playbook_general_deploy.yml | 22 ++--- requirements.yml | 1 - roles/munin-node/.github/FUNDING.yml | 4 + roles/munin-node/.github/stale.yml | 56 ++++++++++++ roles/munin-node/.gitignore | 3 + roles/munin-node/.travis.yml | 30 +++++++ roles/munin-node/.yamllint | 6 ++ roles/munin-node/LICENSE | 20 +++++ roles/munin-node/README.md | 86 +++++++++++++++++++ roles/munin-node/defaults/main.yml | 34 ++++++++ roles/munin-node/files/package.use.munin | 1 + roles/munin-node/handlers/main.yml | 3 + roles/munin-node/meta/.galaxy_install_info | 1 + roles/munin-node/meta/main.yml | 27 ++++++ .../munin-node/molecule/default/converge.yml | 21 +++++ .../munin-node/molecule/default/molecule.yml | 21 +++++ .../molecule/default/playbook-vars.yml | 36 ++++++++ roles/munin-node/tasks/main.yml | 58 +++++++++++++ roles/munin-node/templates/munin-node.conf.j2 | 68 +++++++++++++++ roles/munin-node/templates/plugin-conf.j2 | 7 ++ roles/munin-node/vars/Debian.yml | 3 + roles/munin-node/vars/Gentoo.yml | 4 + roles/munin-node/vars/RedHat.yml | 3 + 24 files changed, 500 insertions(+), 18 deletions(-) create mode 100644 roles/munin-node/.github/FUNDING.yml create mode 100644 roles/munin-node/.github/stale.yml create mode 100644 roles/munin-node/.gitignore create mode 100644 roles/munin-node/.travis.yml create mode 100644 roles/munin-node/.yamllint create mode 100644 roles/munin-node/LICENSE create mode 100644 roles/munin-node/README.md create mode 100644 roles/munin-node/defaults/main.yml create mode 100644 roles/munin-node/files/package.use.munin create mode 100644 roles/munin-node/handlers/main.yml create mode 100644 roles/munin-node/meta/.galaxy_install_info create mode 100644 roles/munin-node/meta/main.yml create mode 100644 roles/munin-node/molecule/default/converge.yml create mode 100644 roles/munin-node/molecule/default/molecule.yml create mode 100644 roles/munin-node/molecule/default/playbook-vars.yml create mode 100644 roles/munin-node/tasks/main.yml create mode 100644 roles/munin-node/templates/munin-node.conf.j2 create mode 100644 roles/munin-node/templates/plugin-conf.j2 create mode 100644 roles/munin-node/vars/Debian.yml create mode 100644 roles/munin-node/vars/Gentoo.yml create mode 100644 roles/munin-node/vars/RedHat.yml diff --git a/group_vars/all/all.yml b/group_vars/all/all.yml index bf9ad08..4085c54 100644 --- a/group_vars/all/all.yml +++ b/group_vars/all/all.yml @@ -23,6 +23,3 @@ main_domain: wirebrass.fr # Certbot admin Email address certbot_admin_email: contact@wirebrass.fr -# Bind munin-node to localhost -munin_node_bind_host: "127.0.0.1" - diff --git a/playbook_general_deploy.yml b/playbook_general_deploy.yml index dc2ac72..2168a12 100644 --- a/playbook_general_deploy.yml +++ b/playbook_general_deploy.yml @@ -1,18 +1,12 @@ --- - hosts: all roles: - - auto_reboot - - auto_upgrade - - client_ntp - - client_resolvers - - client_tools - - users_sudo - - client_iptables +# - auto_reboot +# - auto_upgrade +# - client_ntp +# - client_resolvers +# - client_tools +# - users_sudo +# - client_iptables + - munin-node -- hosts: os_centos - roles: - - geerlingguy.munin-node - -- hosts: os_debian - roles: - - geerlingguy.munin-node diff --git a/requirements.yml b/requirements.yml index d837c4c..adcc6ab 100644 --- a/requirements.yml +++ b/requirements.yml @@ -2,4 +2,3 @@ - name: geerlingguy.munin - name: geerlingguy.nginx - name: geerlingguy.certbot -- name: geerlingguy.munin-node diff --git a/roles/munin-node/.github/FUNDING.yml b/roles/munin-node/.github/FUNDING.yml new file mode 100644 index 0000000..96b4938 --- /dev/null +++ b/roles/munin-node/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms +--- +github: geerlingguy +patreon: geerlingguy diff --git a/roles/munin-node/.github/stale.yml b/roles/munin-node/.github/stale.yml new file mode 100644 index 0000000..c7ff127 --- /dev/null +++ b/roles/munin-node/.github/stale.yml @@ -0,0 +1,56 @@ +# Configuration for probot-stale - https://github.com/probot/stale + +# Number of days of inactivity before an Issue or Pull Request becomes stale +daysUntilStale: 90 + +# Number of days of inactivity before an Issue or Pull Request with the stale label is closed. +# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. +daysUntilClose: 30 + +# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) +onlyLabels: [] + +# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable +exemptLabels: + - pinned + - security + - planned + +# Set to true to ignore issues in a project (defaults to false) +exemptProjects: false + +# Set to true to ignore issues in a milestone (defaults to false) +exemptMilestones: false + +# Set to true to ignore issues with an assignee (defaults to false) +exemptAssignees: false + +# Label to use when marking as stale +staleLabel: stale + +# Limit the number of actions per hour, from 1-30. Default is 30 +limitPerRun: 30 + +pulls: + markComment: |- + This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution! + + Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark pull requests as stale. + + unmarkComment: >- + This pull request is no longer marked for closure. + + closeComment: >- + This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details. + +issues: + markComment: |- + This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! + + Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. + + unmarkComment: >- + This issue is no longer marked for closure. + + closeComment: >- + This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. diff --git a/roles/munin-node/.gitignore b/roles/munin-node/.gitignore new file mode 100644 index 0000000..f56f5b5 --- /dev/null +++ b/roles/munin-node/.gitignore @@ -0,0 +1,3 @@ +*.retry +*/__pycache__ +*.pyc diff --git a/roles/munin-node/.travis.yml b/roles/munin-node/.travis.yml new file mode 100644 index 0000000..bef345c --- /dev/null +++ b/roles/munin-node/.travis.yml @@ -0,0 +1,30 @@ +--- +language: python +services: docker + +env: + global: + - ROLE_NAME: munin-node + matrix: + - MOLECULE_DISTRO: centos7 + - MOLECULE_DISTRO: ubuntu1804 + + - MOLECULE_DISTRO: centos7 + MOLECULE_PLAYBOOK: playbook-vars.yml + +install: + # Install test dependencies. + - pip install molecule yamllint ansible-lint docker + +before_script: + # Use actual Ansible Galaxy role name for the project directory. + - cd ../ + - mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME + - cd geerlingguy.$ROLE_NAME + +script: + # Run tests. + - molecule test + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/roles/munin-node/.yamllint b/roles/munin-node/.yamllint new file mode 100644 index 0000000..a3dbc38 --- /dev/null +++ b/roles/munin-node/.yamllint @@ -0,0 +1,6 @@ +--- +extends: default +rules: + line-length: + max: 120 + level: warning diff --git a/roles/munin-node/LICENSE b/roles/munin-node/LICENSE new file mode 100644 index 0000000..4275cf3 --- /dev/null +++ b/roles/munin-node/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2017 Jeff Geerling + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/roles/munin-node/README.md b/roles/munin-node/README.md new file mode 100644 index 0000000..4637c35 --- /dev/null +++ b/roles/munin-node/README.md @@ -0,0 +1,86 @@ +# Ansible Role: Munin Node + +[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-munin-node.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-munin-node) + +Installs munin-node, a monitoring system endpoint, on RedHat/CentOS, Gentoo or Debian/Ubuntu Linux servers. + +## Requirements + +If using RedHat/CentOS, make sure you have the EPEL repository installed prior to using this role (you can install it using the [`geerlingguy.repo-epel`](https://galaxy.ansible.com/list#/roles/436) role). + +## Role Variables + +Available variables are listed below, along with default values: + + munin_node_bind_host: "*" + munin_node_bind_port: "4949" + +The host and port to which munin-node will bind. Common host options are `127.0.0.1` (localhost), or `*` (bind to all IP addresses). `4949` is the default Munin port. + + munin_node_host_name: '' + +Set this explicitly if the munin master doesn't report the correct hostname when telnetting in to munin-node. In most cases, the default should work fine. + + munin_node_allowed_ips: + - '^127\.0\.0\.1$' + - '^::1$' + +A list of IP addresses formatted as a python-style regular expression. Must use single quotes to allow the proper regex escaping to pass through to the configuration file. Hosts with these IP addresses will be allowed to connect to the server and get detailed system stats via munin-node. + + munin_node_allowed_cidrs: [] + +A list of IP networks in CIDR format, for instance `10.0.0.0/8`. Hosts with an IP address in one of these networks will be allowed to connect to the server and get detailed system stats via munin-node. + + munin_node_denied_cidrs: [] + +A list of IP networks in CIDR format, for instance `10.42.0.0/16`. Hosts with an IP address in one of these networks will be denied access to the server. This takes precedence over `munin_node_allowed_cidrs`: an IP address that matches both a network in `munin_node_allowed_cidrs` and a network in `munin_node_denied_cidrs` will be denied access. + +### Munin Plugin Configuration + +You can enable plugins using the `munin_node_plugins` list, like so: + + munin_node_plugins: + - name: uptime + +If the name of the resulting plugin does not match the name of the munin plugin from which it is generated (as is the case, say, with the `if_` plugin), you need to add a `plugin` field to the list item, like so: + + munin_node_plugins: + - name: if_eth0 + plugin: if_ + +#### Plugin settings + +If you need to add plugin configuration for plugins you've added via `munin_node_plugins`, you can do so with a simple hashmap that has the plugin name (which will be the `[plugin]` section in the resulting configuration file), and a list of variable names and values. For example: + + munin_node_config: { + "ps_test": { + "env.regex": "bash", + "env.name": "bash" + } + } + +This configuration will generate a configuration file at `/etc/munin/plugin-conf.d/ansible.conf` with the following contents: + + [ps_test] + env.regex bash + env.name bash + +## Dependencies + +None. + +## Example Playbook + + - hosts: servers + roles: + - { role: geerlingguy.munin-node } + +## License + +MIT / BSD + +## Author Information + +This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). + +Munin plugin configuration was added by Rafał Trójniak . diff --git a/roles/munin-node/defaults/main.yml b/roles/munin-node/defaults/main.yml new file mode 100644 index 0000000..c527b22 --- /dev/null +++ b/roles/munin-node/defaults/main.yml @@ -0,0 +1,34 @@ +--- +munin_node_bind_host: "*" +munin_node_bind_port: "4949" + +munin_node_host_name: '' + +# Munin requires IPs be added as regular expressions. +munin_node_allowed_ips: + - '^127\.0\.0\.1$' + - '^::1$' + +munin_node_allowed_cidrs: [] +munin_node_denied_cidrs: [] + +# Source and destination of munin plugins. +munin_plugin_src_path: /usr/share/munin/plugins/ +munin_plugin_dest_path: /etc/munin/plugins/ + +# List of munin plugins to enable. +munin_node_plugins: [] +# - name: uptime +# - name: if_eth0 +# plugin: if_ +# - name: ps_test +# plugin: ps_ + +# Plugin configuration options (the key is the plugin heading, items within will +# be options for the plugin). +munin_node_config: { +# "ps_test": { +# "env.regex": "bash", +# "env.name": "bash" +# } +} diff --git a/roles/munin-node/files/package.use.munin b/roles/munin-node/files/package.use.munin new file mode 100644 index 0000000..8a624a9 --- /dev/null +++ b/roles/munin-node/files/package.use.munin @@ -0,0 +1 @@ +net-analyzer/munin ipv6 ssl minimal diff --git a/roles/munin-node/handlers/main.yml b/roles/munin-node/handlers/main.yml new file mode 100644 index 0000000..7e0530b --- /dev/null +++ b/roles/munin-node/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart munin-node + service: name=munin-node state=restarted diff --git a/roles/munin-node/meta/.galaxy_install_info b/roles/munin-node/meta/.galaxy_install_info new file mode 100644 index 0000000..928bfda --- /dev/null +++ b/roles/munin-node/meta/.galaxy_install_info @@ -0,0 +1 @@ +{install_date: 'Sat Jul 11 19:42:25 2020', version: 1.3.0} diff --git a/roles/munin-node/meta/main.yml b/roles/munin-node/meta/main.yml new file mode 100644 index 0000000..accc448 --- /dev/null +++ b/roles/munin-node/meta/main.yml @@ -0,0 +1,27 @@ +--- +dependencies: [] + +galaxy_info: + # See: https://github.com/ansible/galaxy/issues/2393 + # role_name: munin-node + author: geerlingguy + description: Munin node monitoring endpoint for RedHat/CentOS or Debian/Ubuntu. + company: "Midwestern Mac, LLC" + license: "license (BSD, MIT)" + min_ansible_version: 2.4 + platforms: + - name: Debian + versions: + - all + - name: Ubuntu + versions: + - all + - name: EL + versions: + - 6 + - 7 + galaxy_tags: + - monitoring + - system + - munin + - metrics diff --git a/roles/munin-node/molecule/default/converge.yml b/roles/munin-node/molecule/default/converge.yml new file mode 100644 index 0000000..7c66f4c --- /dev/null +++ b/roles/munin-node/molecule/default/converge.yml @@ -0,0 +1,21 @@ +--- +- name: Converge + hosts: all + become: true + + pre_tasks: + - name: Update apt cache. + apt: update_cache=true + when: ansible_os_family == 'Debian' + changed_when: false + + - name: Install test dependencies (Debian). + package: name=netcat state=present + when: ansible_os_family == 'Debian' + + - name: Install test dependencies (RedHat). + package: name=nc state=present + when: ansible_os_family == 'RedHat' + + roles: + - role: geerlingguy.munin-node diff --git a/roles/munin-node/molecule/default/molecule.yml b/roles/munin-node/molecule/default/molecule.yml new file mode 100644 index 0000000..2da47dd --- /dev/null +++ b/roles/munin-node/molecule/default/molecule.yml @@ -0,0 +1,21 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: | + set -e + yamllint . + ansible-lint +platforms: + - name: instance + image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible + playbooks: + converge: ${MOLECULE_PLAYBOOK:-converge.yml} diff --git a/roles/munin-node/molecule/default/playbook-vars.yml b/roles/munin-node/molecule/default/playbook-vars.yml new file mode 100644 index 0000000..8156fab --- /dev/null +++ b/roles/munin-node/molecule/default/playbook-vars.yml @@ -0,0 +1,36 @@ +--- +- name: Converge + hosts: all + become: true + + vars: + munin_node_allowed_cidrs: ['10.0.0.0/8', '2001:db8::/32'] + munin_node_denied_cidrs: ['10.42.0.0/16', '2001:db8:42::/48'] + munin_node_plugins: + - name: uptime + - name: if_eth1 + plugin: if_ + + munin_node_config: { + "ps_test": { + "env.regex": "bash", + "env.name": "bash" + } + } + + pre_tasks: + - name: Update apt cache. + apt: update_cache=true cache_valid_time=600 + when: ansible_os_family == 'Debian' + changed_when: false + + - name: Install test dependencies (Debian). + package: name=netcat state=present + when: ansible_os_family == 'Debian' + + - name: Install test dependencies (RedHat). + package: name=nc state=present + when: ansible_os_family == 'RedHat' + + roles: + - role: geerlingguy.munin-node diff --git a/roles/munin-node/tasks/main.yml b/roles/munin-node/tasks/main.yml new file mode 100644 index 0000000..af77cb1 --- /dev/null +++ b/roles/munin-node/tasks/main.yml @@ -0,0 +1,58 @@ +--- +- name: Include OS-specific variables. + include_vars: "{{ ansible_os_family }}.yml" + +- name: Ensure munin-node is installed (RedHat). + yum: name=munin-node state=present enablerepo=epel + when: ansible_os_family == 'RedHat' + +- name: Ensure munin-node is installed (Debian). + apt: name=munin-node state=present + when: ansible_os_family == 'Debian' + +- name: Munin (node) USE flag configuration (Gentoo). + copy: + src: package.use.munin + dest: /etc/portage/package.use/munin + owner: root + group: root + mode: 0644 + when: ansible_os_family == 'Gentoo' + +- name: Ensure munin (node) is installed (Gentoo). + portage: + name: munin + newuse: yes + changed_use: yes + state: latest + when: ansible_os_family == 'Gentoo' + notify: restart munin-node + +- name: Copy munin-node configuration. + template: + src: munin-node.conf.j2 + dest: /etc/munin/munin-node.conf + owner: root + group: root + mode: 0644 + notify: restart munin-node + +- name: Generate plugin configuration. + template: + src: plugin-conf.j2 + dest: /etc/munin/plugin-conf.d/ansible.conf + owner: root + group: root + mode: 0644 + notify: restart munin-node + +- name: Enable additional plugins. + file: + path: "{{ munin_plugin_dest_path }}{{ item.name }}" + src: "{{ munin_plugin_src_path }}{{ item.plugin | default( item.name ) }}" + state: link + with_items: "{{ munin_node_plugins }}" + notify: restart munin-node + +- name: Ensure munin-node is running. + service: name=munin-node state=started enabled=yes diff --git a/roles/munin-node/templates/munin-node.conf.j2 b/roles/munin-node/templates/munin-node.conf.j2 new file mode 100644 index 0000000..7fa03c6 --- /dev/null +++ b/roles/munin-node/templates/munin-node.conf.j2 @@ -0,0 +1,68 @@ +# +# Example config-file for munin-node +# + +log_level 4 +log_file {{ munin_node_log }} +pid_file {{ munin_node_pid }} + +background 1 +setsid 1 + +user root +group root + +# This is the timeout for the whole transaction. +# Units are in sec. Default is 15 min +# global_timeout 900 + +# This is the timeout for each plugin. +# Units are in sec. Default is 1 min +# timeout 60 + +# Regexps for files to ignore +ignore_file [\#~]$ +ignore_file DEADJOE$ +ignore_file \.bak$ +ignore_file %$ +ignore_file \.dpkg-(tmp|new|old|dist)$ +ignore_file \.rpm(save|new)$ +ignore_file \.pod$ + +# Set this if the client doesn't report the correct hostname when +# telnetting to localhost, port 4949 +{% if munin_node_host_name %} +host_name {{ munin_node_host_name }} +{% endif %} + +# A list of addresses that are allowed to connect. This must be a +# regular expression, since Net::Server does not understand CIDR-style +# network notation unless the perl module Net::CIDR is installed. You +# may repeat the allow line as many times as you'd like + +{% for allowed_ip in munin_node_allowed_ips %} +allow {{ allowed_ip }} +{% endfor %} + +# If you have installed the Net::CIDR perl module, you can use one or more +# cidr_allow and cidr_deny address/mask patterns. A connecting client must +# match any cidr_allow, and not match any cidr_deny. Note that a netmask +# *must* be provided, even if it's /32 +# +# Example: +# +# cidr_allow 127.0.0.1/32 +# cidr_allow 192.0.2.0/24 +# cidr_deny 192.0.2.42/32 +{% for allowed_cidr in munin_node_allowed_cidrs %} +cidr_allow {{ allowed_cidr }} +{% endfor %} +{% for denied_cidr in munin_node_denied_cidrs %} +cidr_deny {{ denied_cidr }} +{% endfor %} + +# Which address to bind to; +host {{ munin_node_bind_host }} + +# And which port +port {{ munin_node_bind_port }} diff --git a/roles/munin-node/templates/plugin-conf.j2 b/roles/munin-node/templates/plugin-conf.j2 new file mode 100644 index 0000000..90107fb --- /dev/null +++ b/roles/munin-node/templates/plugin-conf.j2 @@ -0,0 +1,7 @@ +{% for section,directives in munin_node_config.items() | list %} +[{{section}}] +{% for name,val in directives.items() | list %} +{{ name }} {{ val }} +{% endfor %} + +{% endfor %} diff --git a/roles/munin-node/vars/Debian.yml b/roles/munin-node/vars/Debian.yml new file mode 100644 index 0000000..a7d2947 --- /dev/null +++ b/roles/munin-node/vars/Debian.yml @@ -0,0 +1,3 @@ +--- +munin_node_log: /var/log/munin/munin-node.log +munin_node_pid: /var/run/munin/munin-node.pid diff --git a/roles/munin-node/vars/Gentoo.yml b/roles/munin-node/vars/Gentoo.yml new file mode 100644 index 0000000..7f28f1f --- /dev/null +++ b/roles/munin-node/vars/Gentoo.yml @@ -0,0 +1,4 @@ +--- +munin_node_log: /var/log/munin/munin-node.log +munin_node_pid: /var/run/munin-node.pid +munin_plugin_src_path: /usr/libexec/munin/plugins diff --git a/roles/munin-node/vars/RedHat.yml b/roles/munin-node/vars/RedHat.yml new file mode 100644 index 0000000..b5f3c43 --- /dev/null +++ b/roles/munin-node/vars/RedHat.yml @@ -0,0 +1,3 @@ +--- +munin_node_log: /var/log/munin-node/munin-node.log +munin_node_pid: /var/run/munin/munin-node.pid