commit bf5b28933c4c4279de505eddf43dbb3a2554650a Author: decentral1se Date: Mon May 30 17:00:00 2022 +0200 init diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..80e03ee --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +autonomic.netdata: Install and configure Netdata how we need it +Copyright (C) 2022 Autonomic Co-operative + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . diff --git a/README.md b/README.md new file mode 100644 index 0000000..3416c08 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# autonomic.netdata diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..40713ef --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +netdata_upgrade: true diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..28f59ef --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart netdata + service: + name: netdata + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..d6f09ca --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,14 @@ +--- +dependencies: [] + +galaxy_info: + author: autonomic + description: | + Install and configure Netdata how we need it. + company: Autonomic + license: GPLv3 + min_ansible_version: 2.9 + platforms: + - name: Debian + versions: + - buster diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..edbb927 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,17 @@ +--- +- name: Converge + hosts: all + vars: + netdata_alerta_api_key: bazbang + netdata_alerta_recipient: foobar + netdata_alerta_web_hook_url: barfoo + tasks: + - name: "Include autonomic.netdata (install)" + include_role: + name: autonomic.netdata + + - name: "Include autonomic.netdata (upgrade)" + vars: + netdata_upgrade: true + include_role: + name: autonomic.netdata diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..915192b --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,31 @@ +--- +dependency: + name: galaxy +driver: + name: hetznercloud +platforms: + - name: "autonomic.netdata-${INSTANCE_UUID}" + server_type: "cx11" + image: "debian-10" +provisioner: + name: ansible +lint: | + set -e + yamllint -c ../../.yamllint.yml . + ansible-lint -c ../../.ansible-lint.yml . +scenario: + test_sequence: + - lint + - dependency + - cleanup + - destroy + - syntax + - create + - prepare + - converge + # TODO(decentral1se): Quick fix for https://git.autonomic.zone/autonomic-cooperative/infrastructure/issues/166 + # - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/tasks/alerta.yml b/tasks/alerta.yml new file mode 100644 index 0000000..590fc35 --- /dev/null +++ b/tasks/alerta.yml @@ -0,0 +1,19 @@ +--- +- name: Add alerta web hook + no_log: true + lineinfile: + line: ALERTA_WEBHOOK_URL="{{ netdata_alerta_web_hook_url }}" + dest: /etc/netdata/health_alarm_notify.conf + regexp: "^ALERTA_WEBHOOK_URL" + +- name: Add alerta API key + lineinfile: + line: ALERTA_API_KEY="{{ netdata_alerta_api_key }}" + dest: /etc/netdata/health_alarm_notify.conf + regexp: "^ALERTA_API_KEY" + +- name: Add alerta recipient + lineinfile: + line: DEFAULT_RECIPIENT_ALERTA="{{ netdata_alerta_recipient }}" + dest: /etc/netdata/health_alarm_notify.conf + regexp: "^DEFAULT_RECIPIENT_ALERTA" diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..06dc03f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,43 @@ +--- +- name: Ensure mandatory variables are configured + assert: + that: "{{ item }} is defined" + fail_msg: "You must define the '{{ item }}' variable" + with_items: + - netdata_alerta_api_key + - netdata_alerta_recipient + - netdata_alerta_web_hook_url + +- name: Check if netdata installation present + stat: + path: /etc/netdata/.environment + register: netdata_install + +- name: Download the installer script + get_url: + url: https://my-netdata.io/kickstart.sh + dest: /tmp/netdata-kickstart.sh + mode: a+x + force: true + when: not netdata_install.stat.exists or netdata_upgrade + +- name: Run netdata installer script (install/ugrade as required) + command: | + bash /tmp/netdata-kickstart.sh + --dont-wait + --stable-channel + --disable-cloud + when: not netdata_install.stat.exists or netdata_upgrade + notify: Restart netdata + +- name: Ensure health_alarm_notify script is in /etc/netdata + copy: + src: /usr/lib/netdata/conf.d/health_alarm_notify.conf + dest: /etc/netdata/health_alarm_notify.conf + remote_src: true + force: false + when: not netdata_install.stat.exists + +- name: Include alerta configuration tasks + include: alerta.yml + when: not netdata_install.stat.exists