From 08e40e4a45d715a367dbd60e3fe89553ce479d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Mon, 1 Mar 2021 18:18:24 +0100 Subject: initial import from private repo --- .yamllint | 33 +++++++++++++++++ README.md | 38 ++++++++++++++++++++ defaults/main.yml | 29 +++++++++++++++ handlers/main.yml | 6 ++++ meta/main.yml | 58 ++++++++++++++++++++++++++++++ molecule/default/INSTALL.rst | 15 ++++++++ molecule/default/converge.yml | 7 ++++ molecule/default/molecule.yml | 27 ++++++++++++++ molecule/default/prepare.yml | 8 +++++ molecule/default/verify.yml | 10 ++++++ tasks/main.yml | 67 +++++++++++++++++++++++++++++++++++ tasks/uninstall.yml | 13 +++++++ templates/health_alarm_notify.conf.j2 | 9 +++++ templates/netdata.conf.j2 | 6 ++++ templates/stream.conf.j2 | 15 ++++++++ tests/inventory | 2 ++ tests/test.yml | 5 +++ vars/main.yml | 2 ++ 18 files changed, 350 insertions(+) create mode 100644 .yamllint create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 molecule/default/INSTALL.rst create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/prepare.yml create mode 100644 molecule/default/verify.yml create mode 100644 tasks/main.yml create mode 100644 tasks/uninstall.yml create mode 100644 templates/health_alarm_notify.conf.j2 create mode 100644 templates/netdata.conf.j2 create mode 100644 templates/stream.conf.j2 create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 vars/main.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/README.md b/README.md new file mode 100644 index 0000000..d4a2e18 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Netdata\_straight +========= + +A pretty straightforward role to install netdata using curl | bash install + +Requirements +------------ + +None + +Role Variables +-------------- + +See [defaults/main.yml] + +Dependencies +------------ + +None + +Example Playbook +---------------- + +``` + - hosts: servers + roles: + - { role: ansible_straight, netdata_installer: kickstart-static64 } +``` + +License +------- + +BSD + +Author Information +------------------ + +Fretlink diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..822acf6 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,29 @@ +--- +# Force installation even if netdata is already installed +netdata_force_install: false +netdata_installer: kickstart +netdata_install_options: "--disable-telemetry" +netdata_uninstall_before: no +netdata_prefix: "{{ (netdata_installer == 'kickstart') | ternary('','/opt/netdata') }}" +# A dict whcih reflect the wanted netdata.conf file +netdata_config: + global: + history: 3996 + + web: + "listen to": 127.0.0.1 + +# Define streaming configuration +#netdata_streaming_configuration: {} +netdata_streaming_configuration: + upstream: + destination: collector.example.com + "api key": XXXXXXX + downstreams: + - name: main + api_key: XXXXXXY + +# Define alarm notify configuration +netdata_alarm_notify_configs: {} +# Define a custom_sender function to be used in alarm configuration +netdata_custom_sender_function: "" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..33291a6 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,6 @@ +--- +# handlers file for netdata-straight +- name: restart netdata + service: + name: netdata + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..4edfb50 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,58 @@ +galaxy_info: + role_name: netdata_straight + author: fretlink + description: A role to install netdata using kickstart installer + company: Fretlink + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: BSD-3-Clause + + min_ansible_version: 2.8 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + platforms: + - name: Ubuntu + versions: + - 18.04 + - 20.04 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/molecule/default/INSTALL.rst b/molecule/default/INSTALL.rst new file mode 100644 index 0000000..c615318 --- /dev/null +++ b/molecule/default/INSTALL.rst @@ -0,0 +1,15 @@ +******* +Delegated driver installation guide +******* + +Requirements +============ + +This driver is delegated to the developer. Up to the developer to implement +requirements. + +Install +======= + +This driver is delegated to the developer. Up to the developer to implement +requirements. diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..20810f0 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include netdata-straight" + include_role: + name: "netdata_straight" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..82a338d --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,27 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: | + set -e + yamllint . + ansible-lint + flake8 +platforms: + - name: instance + image: jrei/systemd-${MOLECULE_OS:-ubuntu:20.04} + privileged: true + command: /lib/systemd/systemd + tmpfs: + - /run + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro +provisioner: + name: ansible + inventory: + host_vars: + instance: + netdata_installer: ${MOLECULE_NETDATA_INSTALLER:-kickstart} +verifier: + name: ansible diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml new file mode 100644 index 0000000..99ab4e9 --- /dev/null +++ b/molecule/default/prepare.yml @@ -0,0 +1,8 @@ +- name: Prepare + hosts: all + tasks: + - name: Update apt cache + apt: + update_cache: yes + become: true + when: ansible_os_family == 'Debian' diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..79044cd --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,10 @@ +--- +# This is an example playbook to execute Ansible tests. + +- name: Verify + hosts: all + gather_facts: false + tasks: + - name: Example assertion + assert: + that: true diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..ca849a3 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,67 @@ +--- +- name: Install requirements (Debian family) + apt: + name: curl + state: present + when: ansible_os_family == 'Debian' + +- name: Install requirements (Redhat family) + yum: + name: curl + state: present + when: ansible_os_family == 'RedHat' + +- name: Check if netdata is installed + command: "{{ prefix }}netdata -V" + ignore_errors: true + register: netdata_installed_st + changed_when: false + vars: + prefix: "{{ netdata_prefix | ternary(netdata_prefix~'/bin/', '') }}" + +- name: Uninstall netdata + include: uninstall.yml + when: + - netdata_uninstall_before is defined + - netdata_uninstall_before | bool + +- name: Install netdata + shell: + cmd: bash <(curl -Ss https://my-netdata.io/{{ netdata_installer }}.sh) --dont-wait {{ netdata_install_options }} + args: + executable: /bin/bash + when: + - netdata_installed_st is failed or netdata_force_install or netdata_uninstall_before + +- name: Configure netdata + template: + src: netdata.conf.j2 + dest: "{{ netdata_prefix }}/etc/netdata/netdata.conf" + owner: root + group: root + mode: 0644 + notify: restart netdata + +- name: Configure streaming + template: + src: stream.conf.j2 + dest: "{{ netdata_prefix }}/etc/netdata/stream.conf" + owner: root + group: netdata + mode: 0640 + when: + - netdata_streaming_configuration is defined + - netdata_streaming_configuration | count > 0 + notify: restart netdata + +- name: Configure netdata alarm notifications + template: + dest: "{{ netdata_prefix }}/etc/netdata/health_alarm_notify.conf" + src: "health_alarm_notify.conf.j2" + owner: netdata + group: root + mode: 0640 + when: + - netdata_alarm_notify_configs is defined + - netdata_alarm_notify_configs | count > 0 + notify: restart netdata diff --git a/tasks/uninstall.yml b/tasks/uninstall.yml new file mode 100644 index 0000000..1b2c4b9 --- /dev/null +++ b/tasks/uninstall.yml @@ -0,0 +1,13 @@ +- name: Check uninstaller presence + stat: + path: "{{ item }}/netdata-uninstaller.sh" + loop: + - /usr/libexec/netdata + - /opt/netdata/usr/libexec/netdata + register: uninstaller_presence + +- name: Uninstall + command: "{{ item }} --yes --force" # noqa 301 + loop: "{{ uninstallers }}" + vars: + uninstallers: "{{ uninstaller_presence.results | selectattr('stat.exists') | map(attribute='invocation.module_args.path') | list }}" diff --git a/templates/health_alarm_notify.conf.j2 b/templates/health_alarm_notify.conf.j2 new file mode 100644 index 0000000..6623d79 --- /dev/null +++ b/templates/health_alarm_notify.conf.j2 @@ -0,0 +1,9 @@ +{% for key in netdata_alarm_notify_configs %} +{{ key }}="{{ netdata_alarm_notify_configs[key] }}" +{% endfor %} + +{% if netdata_custom_sender_function is defined %} +custom_sender() { +{{ netdata_custom_sender_function }} +} +{% endif %} diff --git a/templates/netdata.conf.j2 b/templates/netdata.conf.j2 new file mode 100644 index 0000000..d22ed37 --- /dev/null +++ b/templates/netdata.conf.j2 @@ -0,0 +1,6 @@ +{% for (section,configuration) in netdata_config | dictsort %} +[{{ section }}] +{% for (key,value) in configuration | dictsort %} + {{ key }} = {{ value }} +{% endfor %} +{% endfor %} diff --git a/templates/stream.conf.j2 b/templates/stream.conf.j2 new file mode 100644 index 0000000..f1fb02d --- /dev/null +++ b/templates/stream.conf.j2 @@ -0,0 +1,15 @@ +{% if netdata_streaming_configuration.upstream is defined %} +[stream] + enabled = yes + destination = {{ netdata_streaming_configuration.upstream["destination"] }} + api key = {{ netdata_streaming_configuration.upstream["api key"] }} +{% endif %} +{% if netdata_streaming_configuration.downstreams is defined %} +{% for downstream in netdata_streaming_configuration.downstreams %} +[{{ downstream.api_key }}] + enabled = yes +{% for (key,value) in downstream | dictsort if not key in ['name','api_key'] %} + {{ key }} = {{ value }} +{% endfor %} +{% endfor %} +{% endif %} 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..72866b0 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - netdata-straight \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..938a3e3 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for netdata-straight \ No newline at end of file -- cgit v1.2.3