mirror of
https://github.com/dj-wasabi/ansible-telegraf.git
synced 2025-07-17 08:46:37 +00:00
20
tasks/FreeBSD.yml
Normal file
20
tasks/FreeBSD.yml
Normal file
@ -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"
|
110
tasks/configure_FreeBSD.yml
Normal file
110
tasks/configure_FreeBSD.yml
Normal file
@ -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
|
@ -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:
|
||||
|
Reference in New Issue
Block a user