diff --git a/README.md b/README.md index 4a350ba..7a666bc 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,16 @@ Design goals are to have a minimal memory footprint with a plugin system so that ## Requirements ### Supported systems + This role supports the following systems: * Red Hat * Debian * Ubuntu * Docker container - * Windows (Best effort) * (Open)Suse + * Windows (Best effort) + * FreeBSD (Best effort) So, you'll need one of those systems.. :-) Please sent Pull Requests or suggestions when you want to use this role for other systems. diff --git a/defaults/main.yml b/defaults/main.yml index 485503c..6356ad6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -17,6 +17,7 @@ telegraf_agent_flush_interval: 10 telegraf_agent_flush_jitter: 0 telegraf_agent_aws_tags: False telegraf_agent_aws_tags_prefix: "" +telegraf_agent_config_path: /etc/telegraf # Docker specific settings telegraf_uid_docker: 998 diff --git a/tasks/FreeBSD.yml b/tasks/FreeBSD.yml index 092ddeb..44d84b4 100644 --- a/tasks/FreeBSD.yml +++ b/tasks/FreeBSD.yml @@ -15,6 +15,10 @@ - name: "FreeBSD | add telegraf_flags for extra plugins" shell: sysrc telegraf_flags="-quiet -config-directory=/usr/local/etc/telegraf.d" + tags: + - skip_ansible_lint - name: "FreeBSD | add telegraf to init" shell: sysrc telegraf_enable="YES" + tags: + - skip_ansible_lint diff --git a/tasks/configure_FreeBSD.yml b/tasks/configure_FreeBSD.yml deleted file mode 100644 index 60921e2..0000000 --- a/tasks/configure_FreeBSD.yml +++ /dev/null @@ -1,110 +0,0 @@ ---- -# 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/configure_linux.yml b/tasks/configure_linux.yml index 59f222f..2038299 100644 --- a/tasks/configure_linux.yml +++ b/tasks/configure_linux.yml @@ -6,6 +6,12 @@ when: - telegraf_agent_aws_tags +- name: "Add prefix path" + set_fact: + telegraf_agent_config_path: /usr/local/etc/telegraf + when: + - ansible_os_family == "FreeBSD" + - name: Retrieve all ec2 tags on the instance ec2_tag: region: '{{ ansible_ec2_placement_region }}' @@ -32,7 +38,7 @@ - name: "Copy the template for versions >= 0.10.0" template: src: telegraf.conf.j2 - dest: /etc/telegraf/telegraf.conf + dest: "{{ telegraf_agent_config_path }}/telegraf.conf" owner: telegraf group: telegraf mode: 0640 @@ -45,7 +51,7 @@ - name: "Check if extra plugins directory exists in case of exclusive" stat: - path: /etc/telegraf/telegraf.d + path: "{{ telegraf_agent_config_path }}/telegraf.d" register: telegraf_directory when: - telegraf_plugins_extra_exclusive @@ -53,7 +59,7 @@ - name: "Delete telegraf extra plugin path" file: state: absent - path: "/etc/telegraf/telegraf.d/" + path: "{{ telegraf_agent_config_path }}/telegraf.d/" when: - telegraf_plugins_extra_exclusive - telegraf_directory.stat.exists @@ -65,7 +71,7 @@ - name: "Create telegraf extra plugin path" file: state: directory - path: "/etc/telegraf/telegraf.d/" + path: "{{ telegraf_agent_config_path }}/telegraf.d/" owner: telegraf group: telegraf mode: 0755 @@ -80,7 +86,7 @@ - name: "Copy telegraf extra plugins" template: src: "telegraf-extra-plugin.conf.j2" - dest: "/etc/telegraf/telegraf.d/{{ item.key }}.conf" + dest: "{{ telegraf_agent_config_path }}/telegraf.d/{{ item.key }}.conf" owner: telegraf group: telegraf mode: 0640 @@ -98,7 +104,7 @@ - name: "Remove telegraf extra plugins" file: - path: "/etc/telegraf/telegraf.d/{{ item.key }}.conf" + path: "{{ telegraf_agent_config_path }}/telegraf.d/{{ item.key }}.conf" state: absent with_dict: "{{ telegraf_plugins_extra }}" loop_control: diff --git a/tasks/main.yml b/tasks/main.yml index df00d83..afff3de 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,11 +26,6 @@ - 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: