Install metricbeats with ansible and the elastic yum repository


Last month I started playing with elastic’s metricbeat and you can say I fell in love at first beat. I’ve created some amazing visualizations with the metrics it produces and am blown away by how much visibility I can get from correlating disparate event streams. A good example of this is being able to see VMware hypervisor utilization, system utilization and HTTP endpoint latency stacked on top of each other. Elastic hosts a yum metricbeat repository and it’s easy to deploy it to Fedora-derived servers with ansible’s templating capabilities and the yum_repository module.

The following tasks from my metricbeat role will create a metricbeat yum repository configuration file, install the metricbeat package, deploy a templated metricbeat configuration file then enable and start the service:

---
# tasks file for metricbeat
- name: Add metricbeat repository
  yum_repository:
    name: metricbeat
    description: Beats Repo
    baseurl: https://artifacts.elastic.co/packages/5.x/yum
    gpgkey: https://packages.elastic.co/GPG-KEY-elasticsearch
    gpgcheck: yes
    enabled: yes
    owner: root
    group: root
    state: present
    mode: 0600

- name: Install metricbeat package
  package:
    pkg={{item}}
    state=installed
  with_items:
    - metricbeat

- name: Create metricbeat configuration file
  template:
    src: metricbeat.yml.j2
    dest: /etc/metricbeat/metricbeat.yml
    owner: root
    group: root
    mode: 0644

- name: Enable the metricbeat systemd service
  systemd:
    name: metricbeat
    enabled: yes
    state: started
    daemon_reload: yes

I’ve simplified the example to illustrate how easy it is to get up and running with metricbeat. Error handling and conditional restart logic are missing from the example above.

This article was posted by Matty on 2017-09-08 14:00:00 -0400 EDT