From 4ab32df6df61659dc2fa92868c6fe697fd1ea9c5 Mon Sep 17 00:00:00 2001 From: Markus Langer Date: Thu, 25 Apr 2019 23:52:06 +0200 Subject: [PATCH] basic FreeBSD support --- tasks/FreeBSD.yml | 20 +++++++ tasks/configure_FreeBSD.yml | 110 ++++++++++++++++++++++++++++++++++++ tasks/main.yml | 10 ++++ 3 files changed, 140 insertions(+) create mode 100644 tasks/FreeBSD.yml create mode 100644 tasks/configure_FreeBSD.yml diff --git a/tasks/FreeBSD.yml b/tasks/FreeBSD.yml new file mode 100644 index 0000000..092ddeb --- /dev/null +++ b/tasks/FreeBSD.yml @@ -0,0 +1,20 @@ +--- +# description: FreeBSD specific installation + +- name: "FreeBSD | set package name" + set_fact: + telegraf_agent_package: telegraf + +- name: "FreeBSD | Install Telegraf package" + pkgng: + name: "{{ telegraf_agent_package }}" + state: "{{ telegraf_agent_package_state }}" + register: is_telegraf_package_installed + until: is_telegraf_package_installed is succeeded + notify: "Restart Telegraf" + +- name: "FreeBSD | add telegraf_flags for extra plugins" + shell: sysrc telegraf_flags="-quiet -config-directory=/usr/local/etc/telegraf.d" + +- name: "FreeBSD | add telegraf to init" + shell: sysrc telegraf_enable="YES" diff --git a/tasks/configure_FreeBSD.yml b/tasks/configure_FreeBSD.yml new file mode 100644 index 0000000..60921e2 --- /dev/null +++ b/tasks/configure_FreeBSD.yml @@ -0,0 +1,110 @@ +--- +# description: Configure telegraf and get all relevent ec2 information + +- name: Retrieve ec2 facts + ec2_metadata_facts: + when: + - telegraf_agent_aws_tags + +- name: Retrieve all ec2 tags on the instance + ec2_tag: + region: '{{ ansible_ec2_placement_region }}' + resource: '{{ ansible_ec2_instance_id }}' + state: list + when: + - telegraf_agent_aws_tags + register: ec2_tags + +- name: "Copy the template for versions >= 0.10.0" + template: + src: telegraf.conf.j2 + dest: /usr/local/etc/telegraf/telegraf.conf + owner: telegraf + group: telegraf + mode: 0640 + become: yes + when: + - telegraf_agent_version is version_compare('0.10.0', '>=') + notify: + - Restart Telegraf + - Restart Telegraf container + +- name: "Check if extra plugins directory exists in case of exclusive" + stat: + path: /usr/local/etc/telegraf.d + register: telegraf_directory + when: + - telegraf_plugins_extra_exclusive + +- name: "Delete telegraf extra plugin path" + file: + state: absent + path: "/usr/local/etc/telegraf.d/" + when: + - telegraf_plugins_extra_exclusive + - telegraf_directory.stat.exists + become: yes + notify: + - Restart Telegraf + - Restart Telegraf container + +- name: "Create telegraf extra plugin path" + file: + state: directory + path: "/usr/local/etc/telegraf.d/" + owner: telegraf + group: telegraf + mode: 0755 + when: + - telegraf_plugins_extra_exclusive + - telegraf_directory.stat.exists + become: yes + notify: + - Restart Telegraf + - Restart Telegraf container + +- name: "Copy telegraf extra plugins" + template: + src: "telegraf-extra-plugin.conf.j2" + dest: "/usr/local/etc/telegraf.d/{{ item.key }}.conf" + owner: telegraf + group: telegraf + mode: 0640 + with_dict: "{{ telegraf_plugins_extra }}" + loop_control: + label: "{{ item.key }}" + when: + - telegraf_plugins_extra is defined + - telegraf_plugins_extra is iterable + - item.value.state|default('present') != 'absent' + become: yes + notify: + - Restart Telegraf + - Restart Telegraf container + +- name: "Remove telegraf extra plugins" + file: + path: "/usr/local/etc/telegraf.d/{{ item.key }}.conf" + state: absent + with_dict: "{{ telegraf_plugins_extra }}" + loop_control: + label: "{{ item.key }}" + when: + - telegraf_plugins_extra is defined + - telegraf_plugins_extra is iterable + - item.value.state|default('present') == 'absent' + become: yes + notify: + - Restart Telegraf + - Restart Telegraf container + +- name: "Force restart service after reread config" + meta: flush_handlers + +- name: "Start Telegraf (If it wasn't running)" + service: + name: telegraf + state: started + enabled: yes + become: yes + when: not telegraf_agent_docker diff --git a/tasks/main.yml b/tasks/main.yml index cf89ad0..df00d83 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,9 +18,19 @@ include_tasks: "Suse.yml" when: ansible_os_family == "Suse" and not telegraf_agent_docker +- name: "Install on FreeBSD" + include_tasks: "FreeBSD.yml" + when: + - ansible_os_family == "FreeBSD" and not telegraf_agent_docker + - include_tasks: "docker.yml" when: telegraf_agent_docker +- name: "Configure Telegraf" + include_tasks: "configure_FreeBSD.yml" + when: + - ansible_os_family == "FreeBSD" + - name: "Configure Telegraf" include_tasks: "configure_linux.yml" when: