openstack-ansible-ops/elk_metrics_6x/installFilebeat.yml
Kevin Carter 26dd0b7a2e
Change filebeat to only execute on hosts
Filebeat has everything it needs to function on the physical host
machines. This change ensures that filebeat is only ever installed and
setup on the physical hosts which will save a lot of IO, and greatly
shorten playbook runtimes.

Change-Id: I5dd9d3ac9dc6871e14568c1591f3de475cba33e2
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2018-04-27 12:24:04 -05:00

168 lines
6.2 KiB
YAML

---
- name: Install Filebeat
hosts: hosts
become: true
vars:
haproxy_ssl: false
vars_files:
- vars/variables.yml
pre_tasks:
- include_tasks: common_task_install_elk_repo.yml
- name: Ensure Filebeat is installed
apt:
name: "{{ item }}"
state: "{{ elk_package_state | default('present') }}"
update_cache: true
with_items:
- filebeat
tags:
- package_install
- name: exit playbook after uninstall
meta: end_play
when:
- elk_package_state | default('present') == 'absent'
tasks:
- name: Check for apache
stat:
path: /etc/apache2
register: apache2
- name: Check for auditd
stat:
path: /etc/audit
register: audit
- name: Check for ceph
stat:
path: /var/log/ceph
register: ceph
- name: Check for cinder
stat:
path: /var/log/cinder
register: cinder
- name: Check for glance
stat:
path: /var/log/glance
register: glance
- name: Check for heat
stat:
path: /var/log/heat
register: heat
- name: Check for horizon
stat:
path: /var/log/horizon
register: horizon
- name: Check for httpd
stat:
path: /var/log/httpd
register: httpd
- name: Check for keystone
stat:
path: /var/log/keystone
register: keystone
- name: Check for mysql
stat:
path: /var/lib/mysql
register: mysql
- name: Check for neutron
stat:
path: /var/log/neutron
register: neutron
- name: Check for nginx
stat:
path: /var/log/nginx
register: nginx
- name: Check for nova
stat:
path: /var/log/nova
register: nova
- name: Check for octavia
stat:
path: /var/log/octavia
register: octavia
- name: Check for swift
stat:
path: /var/log/swift
register: swift
- name: Check for rabbitmq
stat:
path: /var/lib/rabbitmq
register: rabbitmq
- name: Set discovery facts
set_fact:
apache_enabled: "{{ (apache2.stat.exists | bool) or (httpd.stat.exists | bool) }}"
nginx_enabled: "{{ nginx.stat.exists | bool }}"
auditd_enabled: "{{ audit.stat.exists | bool }}"
mysql_enabled: "{{ (mysql.stat.exists | bool) or (inventory_hostname in groups['galera_all'] | default([])) }}"
ceph_enabled: "{{ (ceph.stat.exists | bool) or (inventory_hostname in groups['ceph_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*ceph.*') | list | length) > 0) }}"
cinder_enabled: "{{ (cinder.stat.exists | bool) or (inventory_hostname in groups['cinder_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*cinder.*') | list | length) > 0) }}"
glance_enabled: "{{ (glance.stat.exists | bool) or (inventory_hostname in groups['glance_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*glance.*') | list | length) > 0) }}"
heat_enabled: "{{ (heat.stat.exists | bool) or (inventory_hostname in groups['heat_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*heat.*') | list | length) > 0) }}"
horizon_enabled: "{{ (horizon.stat.exists | bool) or (inventory_hostname in groups['horizon_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*horizon.*') | list | length) > 0) }}"
keystone_enabled: "{{ (keystone.stat.exists | bool) or (inventory_hostname in groups['keystone_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*keystone.*') | list | length) > 0) }}"
neutron_enabled: "{{ (neutron.stat.exists | bool) or (inventory_hostname in groups['neutron_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*neutron.*') | list | length) > 0) }}"
nova_enabled: "{{ (nova.stat.exists | bool) or (inventory_hostname in groups['nova_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*nova.*') | list | length) > 0) }}"
octavia_enabled: "{{ (octavia.stat.exists | bool) or (inventory_hostname in groups['octavia_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*octavia.*') | list | length) > 0) }}"
swift_enabled: "{{ (swift.stat.exists | bool) or (inventory_hostname in groups['swift_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*swift.*') | list | length) > 0) }}"
rabbitmq_enabled: "{{ (rabbitmq.stat.exists | bool) or (inventory_hostname in groups['rabbitmq_all'] | default([])) or (((groups[inventory_hostname + '-host_containers'] | default([])) | select('match', '.*rabbit.*') | list | length) > 0) }}"
post_tasks:
- name: Drop Filebeat conf file
template:
src: templates/filebeat.yml.j2
dest: /etc/filebeat/filebeat.yml
- name: Enable and restart Filebeat
systemd:
name: "filebeat"
enabled: true
state: restarted
- name: Load Filebeat Dashboards
hosts: hosts[0]
become: true
vars_files:
- vars/variables.yml
tasks:
- name: Load templates
shell: >-
{% set IP_ARR=[] %}
{% for host in groups['elastic-logstash'] %}
{% if IP_ARR.insert(loop.index,hostvars[host]['ansible_host']) %}
{% endif %}
{% endfor %}
{% set elasticsearch_hosts = [IP_ARR | map('regex_replace', '$', ':' ~ elastic_port|string()) | map('regex_replace', '$', '"') | map('regex_replace', '^', '"') | list | join(',' )] %}
filebeat setup
{{ item }}
-E 'output.logstash.enabled=false'
-E 'output.elasticsearch.hosts={{ elasticsearch_hosts }}'
-e -v
with_items:
- "--template"
- "--dashboards"
register: templates
until: templates | success
retries: 3
delay: 2