Merge pull request #101 from dj-wasabi/minor-changes-for-freebsd

Some changes for fixing FreeBSD
This commit is contained in:
Werner Dijkerman
2019-04-27 16:22:01 +02:00
committed by GitHub
6 changed files with 20 additions and 122 deletions

View File

@ -15,14 +15,16 @@ Design goals are to have a minimal memory footprint with a plugin system so that
## Requirements ## Requirements
### Supported systems ### Supported systems
This role supports the following systems: This role supports the following systems:
* Red Hat * Red Hat
* Debian * Debian
* Ubuntu * Ubuntu
* Docker container * Docker container
* Windows (Best effort)
* (Open)Suse * (Open)Suse
* Windows (Best effort)
* FreeBSD (Best effort)
So, you'll need one of those systems.. :-) So, you'll need one of those systems.. :-)
Please sent Pull Requests or suggestions when you want to use this role for other systems. Please sent Pull Requests or suggestions when you want to use this role for other systems.

View File

@ -17,6 +17,7 @@ telegraf_agent_flush_interval: 10
telegraf_agent_flush_jitter: 0 telegraf_agent_flush_jitter: 0
telegraf_agent_aws_tags: False telegraf_agent_aws_tags: False
telegraf_agent_aws_tags_prefix: "" telegraf_agent_aws_tags_prefix: ""
telegraf_agent_config_path: /etc/telegraf
# Docker specific settings # Docker specific settings
telegraf_uid_docker: 998 telegraf_uid_docker: 998

View File

@ -15,6 +15,10 @@
- name: "FreeBSD | add telegraf_flags for extra plugins" - name: "FreeBSD | add telegraf_flags for extra plugins"
shell: sysrc telegraf_flags="-quiet -config-directory=/usr/local/etc/telegraf.d" shell: sysrc telegraf_flags="-quiet -config-directory=/usr/local/etc/telegraf.d"
tags:
- skip_ansible_lint
- name: "FreeBSD | add telegraf to init" - name: "FreeBSD | add telegraf to init"
shell: sysrc telegraf_enable="YES" shell: sysrc telegraf_enable="YES"
tags:
- skip_ansible_lint

View File

@ -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

View File

@ -6,6 +6,12 @@
when: when:
- telegraf_agent_aws_tags - 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 - name: Retrieve all ec2 tags on the instance
ec2_tag: ec2_tag:
region: '{{ ansible_ec2_placement_region }}' region: '{{ ansible_ec2_placement_region }}'
@ -32,7 +38,7 @@
- name: "Copy the template for versions >= 0.10.0" - name: "Copy the template for versions >= 0.10.0"
template: template:
src: telegraf.conf.j2 src: telegraf.conf.j2
dest: /etc/telegraf/telegraf.conf dest: "{{ telegraf_agent_config_path }}/telegraf.conf"
owner: telegraf owner: telegraf
group: telegraf group: telegraf
mode: 0640 mode: 0640
@ -45,7 +51,7 @@
- name: "Check if extra plugins directory exists in case of exclusive" - name: "Check if extra plugins directory exists in case of exclusive"
stat: stat:
path: /etc/telegraf/telegraf.d path: "{{ telegraf_agent_config_path }}/telegraf.d"
register: telegraf_directory register: telegraf_directory
when: when:
- telegraf_plugins_extra_exclusive - telegraf_plugins_extra_exclusive
@ -53,7 +59,7 @@
- name: "Delete telegraf extra plugin path" - name: "Delete telegraf extra plugin path"
file: file:
state: absent state: absent
path: "/etc/telegraf/telegraf.d/" path: "{{ telegraf_agent_config_path }}/telegraf.d/"
when: when:
- telegraf_plugins_extra_exclusive - telegraf_plugins_extra_exclusive
- telegraf_directory.stat.exists - telegraf_directory.stat.exists
@ -65,7 +71,7 @@
- name: "Create telegraf extra plugin path" - name: "Create telegraf extra plugin path"
file: file:
state: directory state: directory
path: "/etc/telegraf/telegraf.d/" path: "{{ telegraf_agent_config_path }}/telegraf.d/"
owner: telegraf owner: telegraf
group: telegraf group: telegraf
mode: 0755 mode: 0755
@ -80,7 +86,7 @@
- name: "Copy telegraf extra plugins" - name: "Copy telegraf extra plugins"
template: template:
src: "telegraf-extra-plugin.conf.j2" 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 owner: telegraf
group: telegraf group: telegraf
mode: 0640 mode: 0640
@ -98,7 +104,7 @@
- name: "Remove telegraf extra plugins" - name: "Remove telegraf extra plugins"
file: file:
path: "/etc/telegraf/telegraf.d/{{ item.key }}.conf" path: "{{ telegraf_agent_config_path }}/telegraf.d/{{ item.key }}.conf"
state: absent state: absent
with_dict: "{{ telegraf_plugins_extra }}" with_dict: "{{ telegraf_plugins_extra }}"
loop_control: loop_control:

View File

@ -26,11 +26,6 @@
- include_tasks: "docker.yml" - include_tasks: "docker.yml"
when: telegraf_agent_docker when: telegraf_agent_docker
- name: "Configure Telegraf"
include_tasks: "configure_FreeBSD.yml"
when:
- ansible_os_family == "FreeBSD"
- name: "Configure Telegraf" - name: "Configure Telegraf"
include_tasks: "configure_linux.yml" include_tasks: "configure_linux.yml"
when: when: