Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic FreeBSD support #100

Merged
merged 1 commit into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tasks/FreeBSD.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 110 additions & 0 deletions tasks/configure_FreeBSD.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down