Add speedtest cli to Telegraf config

- Install speedtest CLI on cluster leader
- Install speedtest telegraf config on leader
- cleanup hosts in ping list
- Add custom shell script on leader to output speedtest data to influxdb
- improve version checking of Telegraf binary
- bump telegraf version
- allow ' package-latest' to pass ansible-lint
This commit is contained in:
Nathaniel Landau
2022-04-19 09:17:15 -04:00
parent d0be01b337
commit 73419ec0bd
9 changed files with 802 additions and 15 deletions

View File

@@ -43,6 +43,13 @@
- not mac_arm
fail_msg: "Unable to install Telegraf on this host"
- name: "set variable: Set speedtest download Binary (armv7l)"
ansible.builtin.set_fact:
speedtest_download_file_uri: "https://install.speedtest.net/app/cli/ookla-speedtest-{{ speedtest_cli_version }}-linux-armhf.tgz"
when:
- ansible_os_family == 'Debian'
- ansible_architecture == 'armv7l'
- name: "Install/upgrade Telegraf"
block:
- name: "set fact: Need telegraf install?"
@@ -70,7 +77,7 @@
ignore_errors: true
register: current_telegraf_version
check_mode: false
changed_when: current_telegraf_version.stdout != telegraf_version
changed_when: false
when:
- telegraph_binary_location is defined
- not need_telegraf_install
@@ -81,7 +88,13 @@
when:
- telegraph_binary_location is defined
- not need_telegraf_install
- current_telegraf_version.stdout != telegraf_version
- current_telegraf_version.stdout is version(telegraf_version, '<')
- ansible.builtin.debug:
msg: "Current telegraf version {{ current_telegraf_version.stdout }} is lower than specified {{ telegraf_version }}"
when:
- telegraph_binary_location is defined
- current_telegraf_version.stdout is version(telegraf_version, '<')
- name: install telegraf (MacOS)
community.general.homebrew:
@@ -124,7 +137,9 @@
become: true
ansible.builtin.apt:
pkg: telegraf
state: latest
update_cache: true
only_upgrade: true
notify: restart_telegraf
when:
- ansible_os_family == 'Debian'
@@ -143,6 +158,51 @@
# - need_telegraf_install
# -------------------------------------------------- Add Telegraf Configs
- name: "Install speedtest"
when: "'pis' in group_names"
block:
- name: "set fact: do we need speedtest installed?"
ansible.builtin.set_fact:
need_speedtest_install: false
- name: Check if speedtest is installed
ansible.builtin.stat:
path: /usr/local/bin/speedtest
register: speedtest_binary_file_location
- name: "set fact: do we need a speedtest install"
ansible.builtin.set_fact:
need_speedtest_install: true
when:
- not speedtest_binary_file_location.stat.exists
- name: Check current version of speedtest
ansible.builtin.shell: /usr/local/bin/speedtest --version | head -n1 | awk '{print $4}' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+'
ignore_errors: true
register: current_speedtest_version
check_mode: false
changed_when: false
when:
- not need_speedtest_install
- name: "set fact: do we need a speedtest install"
ansible.builtin.set_fact:
need_speedtest_install: true
when:
- not need_speedtest_install
- current_speedtest_version.stdout is version(speedtest_cli_version, '<')
- name: "Install speedtest (pi)"
become: true
ansible.builtin.unarchive:
src: "{{ speedtest_download_file_uri }}"
dest: /usr/local/bin
remote_src: true
when:
- need_speedtest_install
- ansible_os_family == 'Debian'
- ansible_architecture == 'armv7l'
- name: "Configure Telegraf"
block:
- name: "Ensure {{ telegraph_config_location }} exists"
@@ -176,6 +236,7 @@
mode: "644"
loop:
- { src: "telegraf/leader.conf.j2", dest: "{{ telegraph_config_location }}/telegraf.d/leader.conf" }
- { src: "telegraf/speedtest.conf.j2", dest: "{{ telegraph_config_location }}/telegraf.d/speedtest.conf" }
- { src: "telegraf/pingHosts.conf.j2", dest: "{{ telegraph_config_location }}/telegraf.d/pingHosts.conf" }
when:
- is_cluster_leader
@@ -192,6 +253,17 @@
when:
- inventory_hostname != 'synology'
- name: Copy speedtest script
become: true
ansible.builtin.template:
src: "scripts/telegraf_speedtest.sh.j2"
dest: "/usr/local/bin/telegraf_speedtest.sh"
mode: 0755
owner: "{{ ansible_user_uid }}"
group: "{{ ansible_user_gid }}"
when:
- is_cluster_leader
- name: Reset file ownership
become: true
ansible.builtin.file: