From 22dd9bfb3d2af34fbc065d5e2453484a8135039c Mon Sep 17 00:00:00 2001 From: Jannik Beyerstedt Date: Sun, 2 May 2021 18:19:11 +0200 Subject: [PATCH] Add FreeBSD support --- handlers/main.yml | 17 ----------------- tasks/cronmails.yml | 1 + tasks/telegraf-FreeBSD.yml | 31 +++++++++++++++++++++++++++++++ tasks/telegraf.yml | 19 ++++++++++++++++--- templates/sshd_config.j2 | 2 ++ templates/telegraf.conf.j2 | 11 ++++++++++- 6 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 tasks/telegraf-FreeBSD.yml diff --git a/handlers/main.yml b/handlers/main.yml index 333f373..05af407 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -6,23 +6,6 @@ name: ssh state: restarted -- name: Enable telegraf - service: - name: telegraf - enabled: yes - -- name: Restart telegraf - service: - name: telegraf - state: restarted - -- name: Enable and restart telegraf - become: yes - service: - name: telegraf - state: restarted - enabled: yes - - name: Enable caddy service: name: caddy diff --git a/tasks/cronmails.yml b/tasks/cronmails.yml index ffff41a..3841aa2 100644 --- a/tasks/cronmails.yml +++ b/tasks/cronmails.yml @@ -8,6 +8,7 @@ - "cronmails-{{ ansible_distribution }}.{{ ansible_distribution_release }}.yml" - "cronmails-{{ ansible_distribution }}.yml" - "cronmails-{{ (override_os_family is defined) | ternary(override_os_family,ansible_os_family) }}.yml" + ignore_errors: true # Set cronjob env variables/ settings - name: cronmails - Crontab set path diff --git a/tasks/telegraf-FreeBSD.yml b/tasks/telegraf-FreeBSD.yml new file mode 100644 index 0000000..715da16 --- /dev/null +++ b/tasks/telegraf-FreeBSD.yml @@ -0,0 +1,31 @@ +--- +# Server/Telegraf: Install and Setup Telegraf Monitoring - FreeBSD Version + +- name: telegraf - Install telegraf + become: yes + ansible.builtin.package: + name: telegraf + state: latest + +# # Install SNMP utilities for telegraf monitoring +# - name: telegraf - Install SNMP utilities +# become: yes +# ansible.builtin.package: +# name: "{{ packages }}" +# state: present +# vars: +# packages: +# - snmp +# - snmp-mibs-downloader +# when: telegraf_ubnt_ns_ips is defined + +- name: telegraf - Install SNMP utilities + become: yes + ansible.builtin.package: + name: "{{ packages }}" + state: present + vars: + packages: + - snmp + - snmp-mibs-downloader + when: telegraf_ubnt_ns_ips is defined diff --git a/tasks/telegraf.yml b/tasks/telegraf.yml index 29fb3a2..e499a96 100644 --- a/tasks/telegraf.yml +++ b/tasks/telegraf.yml @@ -33,10 +33,23 @@ when: telegraf_ubnt_ns_ips is defined # Configure -- name: telegraf - Copy telegraf config +- name: telegraf - Copy telegraf config (Linux) become: yes template: src: "{{ role_path }}/templates/telegraf.conf.j2" dest: /etc/telegraf/telegraf.conf - notify: - - Enable and restart telegraf + when: (override_os_family is defined) | ternary(override_os_family,ansible_os_family) != "FreeBSD" + +- name: telegraf - Copy telegraf config (FreeBSD) + become: yes + template: + src: "{{ role_path }}/templates/telegraf.conf.j2" + dest: /usr/local/etc/telegraf.conf + when: (override_os_family is defined) | ternary(override_os_family,ansible_os_family) == "FreeBSD" + +- name: telegraf - Enable and restart telegraf + become: yes + service: + name: telegraf + state: restarted + enabled: yes diff --git a/templates/sshd_config.j2 b/templates/sshd_config.j2 index 6473957..38fce05 100644 --- a/templates/sshd_config.j2 +++ b/templates/sshd_config.j2 @@ -65,6 +65,8 @@ AcceptEnv LANG LC_* # Log sftp level file access (read/write/etc.) that would not be easily logged otherwise. {% if ((override_os_family is defined) | ternary(override_os_family,ansible_os_family)) == 'Centos' %} Subsystem sftp /usr/libexec/openssh/sftp-server -f AUTHPRIV -l INFO +{% elif ((override_os_family is defined) | ternary(override_os_family,ansible_os_family)) == 'FreeBSD' %} +Subsystem sftp /usr/libexec/sftp-server {% else %} Subsystem sftp /usr/lib/openssh/sftp-server -f AUTHPRIV -l INFO {% endif %} diff --git a/templates/telegraf.conf.j2 b/templates/telegraf.conf.j2 index 3a7d899..851902e 100644 --- a/templates/telegraf.conf.j2 +++ b/templates/telegraf.conf.j2 @@ -32,7 +32,7 @@ # Read metrics about disk usage by mount point [[inputs.disk]] # By default, telegraf gather stats for all mountpoints. - mount_points = ["/", "/mnt/volume-nbg1-1"] + mount_points = ["/", "/mnt/volume-nbg1-1", "/zroot", "/zfspool/zfsstore"] ignore_fs = ["tmpfs", "devtmpfs", "devfs", "overlay", "aufs", "squashfs"] fieldpass = ["total", "free", "used_percent"] @@ -83,3 +83,12 @@ data_type = "integer" name_override = "cpu_temp" {% endif %} + +{% if ((override_os_family is defined) | ternary(override_os_family,ansible_os_family)) == 'FreeBSD' %} +# Read metrics of ZFS from arcstats, zfetchstats, vdev_cache_stats, and pools +[[inputs.zfs]] + ## By default, telegraf gather all zfs stats + kstatMetrics = ["arcstats", "zfetchstats", "vdev_cache_stats"] + ## By default, don't gather zpool stats + poolMetrics = true +{% endif %}