mirror of
https://github.com/dj-wasabi/ansible-telegraf.git
synced 2025-07-17 08:46:37 +00:00
Deployment for MacOS
This commit is contained in:
@ -82,3 +82,6 @@ telegraf_win_service_args:
|
|||||||
- -service install
|
- -service install
|
||||||
- -config {{ telegraf_win_install_dir }}\telegraf\telegraf.conf
|
- -config {{ telegraf_win_install_dir }}\telegraf\telegraf.conf
|
||||||
- --config-directory {{ telegraf_win_include }}
|
- --config-directory {{ telegraf_win_include }}
|
||||||
|
|
||||||
|
telegraf_mac_user: user
|
||||||
|
telegraf_mac_group: admin
|
||||||
|
@ -20,3 +20,6 @@
|
|||||||
name: Telegraf
|
name: Telegraf
|
||||||
start_mode: auto
|
start_mode: auto
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
||||||
|
- name: "Restart MacOS Telegraf"
|
||||||
|
shell: brew services restart telegraf
|
||||||
|
@ -22,6 +22,9 @@ galaxy_info:
|
|||||||
- name: Windows
|
- name: Windows
|
||||||
versions:
|
versions:
|
||||||
- all
|
- all
|
||||||
|
- name: MacOS
|
||||||
|
versions:
|
||||||
|
- all
|
||||||
|
|
||||||
galaxy_tags:
|
galaxy_tags:
|
||||||
- monitoring
|
- monitoring
|
||||||
|
14
tasks/MacOS.yml
Normal file
14
tasks/MacOS.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
# description: MacOS specific installation
|
||||||
|
|
||||||
|
- name: "MacOS | set package name"
|
||||||
|
set_fact:
|
||||||
|
telegraf_agent_package: telegraf
|
||||||
|
|
||||||
|
- name: "MacOS | Install Telegraf package"
|
||||||
|
package:
|
||||||
|
name: "{{ telegraf_agent_package }}"
|
||||||
|
state: "{{ telegraf_agent_package_state }}"
|
||||||
|
register: is_telegraf_package_installed
|
||||||
|
until: is_telegraf_package_installed is succeeded
|
||||||
|
notify: "Restart Telegraf"
|
128
tasks/configure_macos.yml
Normal file
128
tasks/configure_macos.yml
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
---
|
||||||
|
# description: Configure telegraf and get all relevent ec2 information
|
||||||
|
|
||||||
|
- name: Retrieve ec2 facts
|
||||||
|
ec2_metadata_facts:
|
||||||
|
when:
|
||||||
|
- telegraf_agent_aws_tags
|
||||||
|
|
||||||
|
- name: "Add prefix path"
|
||||||
|
set_fact:
|
||||||
|
telegraf_agent_config_path: /usr/local/etc
|
||||||
|
when:
|
||||||
|
- ansible_os_family in ["FreeBSD", "Darwin"]
|
||||||
|
|
||||||
|
- 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: etc-opt-telegraf-telegraf.conf.j2
|
||||||
|
dest: /etc/opt/telegraf/telegraf.conf
|
||||||
|
owner: "{{ telegraf_mac_user }}"
|
||||||
|
group: "{{ telegraf_mac_group }}"
|
||||||
|
mode: 0640
|
||||||
|
become: yes
|
||||||
|
when:
|
||||||
|
- telegraf_agent_version is version_compare('0.10.0', '<')
|
||||||
|
notify:
|
||||||
|
- Restart Telegraf
|
||||||
|
- Restart Telegraf container
|
||||||
|
|
||||||
|
- name: "Copy the template for versions >= 0.10.0"
|
||||||
|
template:
|
||||||
|
src: telegraf.conf.j2
|
||||||
|
dest: "{{ telegraf_agent_config_path }}/telegraf.conf"
|
||||||
|
owner: "{{ telegraf_mac_user }}"
|
||||||
|
group: "{{ telegraf_mac_group }}"
|
||||||
|
mode: 0640
|
||||||
|
become: yes
|
||||||
|
when:
|
||||||
|
- telegraf_agent_version is version_compare('0.10.0', '>=')
|
||||||
|
notify:
|
||||||
|
- Restart MacOS Telegraf
|
||||||
|
- Restart Telegraf container
|
||||||
|
|
||||||
|
- name: "Check if extra plugins directory exists in case of exclusive"
|
||||||
|
stat:
|
||||||
|
path: "{{ telegraf_agent_config_path }}/telegraf.d"
|
||||||
|
register: telegraf_directory
|
||||||
|
when:
|
||||||
|
- telegraf_plugins_extra_exclusive
|
||||||
|
|
||||||
|
- name: "Delete telegraf extra plugin path"
|
||||||
|
file:
|
||||||
|
state: absent
|
||||||
|
path: "{{ telegraf_agent_config_path }}/telegraf.d/"
|
||||||
|
when:
|
||||||
|
- telegraf_plugins_extra_exclusive
|
||||||
|
- telegraf_directory.stat.exists
|
||||||
|
become: yes
|
||||||
|
notify:
|
||||||
|
- Restart MacOS Telegraf
|
||||||
|
- Restart Telegraf container
|
||||||
|
|
||||||
|
- name: "Create telegraf extra plugin path"
|
||||||
|
file:
|
||||||
|
state: directory
|
||||||
|
path: "{{ telegraf_agent_config_path }}/telegraf.d/"
|
||||||
|
owner: "{{ telegraf_mac_user }}"
|
||||||
|
group: "{{ telegraf_mac_group }}"
|
||||||
|
mode: 0755
|
||||||
|
when:
|
||||||
|
- telegraf_plugins_extra_exclusive
|
||||||
|
- telegraf_directory.stat.exists
|
||||||
|
become: yes
|
||||||
|
notify:
|
||||||
|
- Restart MacOS Telegraf
|
||||||
|
- Restart Telegraf container
|
||||||
|
|
||||||
|
- name: "Copy telegraf extra plugins"
|
||||||
|
template:
|
||||||
|
src: "telegraf-extra-plugin.conf.j2"
|
||||||
|
dest: "{{ telegraf_agent_config_path }}/telegraf.d/{{ item.key }}.conf"
|
||||||
|
owner: "{{ telegraf_mac_user }}"
|
||||||
|
group: "{{ telegraf_mac_group }}"
|
||||||
|
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 MacOS Telegraf
|
||||||
|
- Restart Telegraf container
|
||||||
|
|
||||||
|
- name: "Remove telegraf extra plugins"
|
||||||
|
file:
|
||||||
|
path: "{{ telegraf_agent_config_path }}/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 MacOS Telegraf
|
||||||
|
- Restart Telegraf container
|
||||||
|
|
||||||
|
- name: "Force restart service after reread config"
|
||||||
|
meta: flush_handlers
|
||||||
|
|
||||||
|
- name: "Start Telegraf (If it wasn't running)"
|
||||||
|
shell: brew services start telegraf
|
||||||
|
register: brew_services_start_telegraf
|
||||||
|
changed_when: '"Successfully started `telegraf`" in brew_services_start_telegraf.stdout'
|
||||||
|
when: not telegraf_agent_docker
|
@ -23,15 +23,25 @@
|
|||||||
when:
|
when:
|
||||||
- ansible_os_family == "FreeBSD" and not telegraf_agent_docker
|
- ansible_os_family == "FreeBSD" and not telegraf_agent_docker
|
||||||
|
|
||||||
|
- name: "Install on MacOS"
|
||||||
|
include_tasks: "MacOS.yml"
|
||||||
|
when:
|
||||||
|
- ansible_os_family == "Darwin" and not telegraf_agent_docker
|
||||||
|
|
||||||
- include_tasks: "docker.yml"
|
- include_tasks: "docker.yml"
|
||||||
when: telegraf_agent_docker
|
when: telegraf_agent_docker
|
||||||
|
|
||||||
- name: "Configure Telegraf"
|
- name: "Configure Telegraf"
|
||||||
include_tasks: "configure_linux.yml"
|
include_tasks: "configure_linux.yml"
|
||||||
when:
|
when:
|
||||||
- ansible_os_family != "Windows"
|
- ansible_os_family not in ['Windows', 'Darwin']
|
||||||
|
|
||||||
- name: "Install / Configure telegraf on Windows"
|
- name: "Install / Configure telegraf on Windows"
|
||||||
include_tasks: "configure_windows.yml"
|
include_tasks: "configure_windows.yml"
|
||||||
when:
|
when:
|
||||||
- ansible_os_family == "Windows" and not telegraf_agent_docker
|
- ansible_os_family == "Windows" and not telegraf_agent_docker
|
||||||
|
|
||||||
|
- name: "Install / Configure telegraf on MacOS"
|
||||||
|
include_tasks: "configure_macos.yml"
|
||||||
|
when:
|
||||||
|
- ansible_os_family == "Darwin" and not telegraf_agent_docker
|
||||||
|
Reference in New Issue
Block a user