2018-06-28 18:10:28 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: APT https transport is enabled
|
|
|
|
apt:
|
|
|
|
name: apt-transport-https
|
|
|
|
state: present
|
|
|
|
tags:
|
2021-05-06 10:42:12 +02:00
|
|
|
- metricbeat
|
|
|
|
- packages
|
|
|
|
|
2021-05-06 11:33:19 +02:00
|
|
|
- name: Elastic embedded GPG key is absent
|
2018-06-28 18:10:28 +02:00
|
|
|
apt_key:
|
2021-05-03 14:23:13 +02:00
|
|
|
id: "D88E42B4"
|
2021-05-06 13:43:59 +02:00
|
|
|
keyring: /etc/apt/trusted.gpg
|
2021-05-03 14:23:13 +02:00
|
|
|
state: absent
|
|
|
|
tags:
|
2021-05-06 10:42:12 +02:00
|
|
|
- metricbeat
|
|
|
|
- packages
|
2021-05-03 14:23:13 +02:00
|
|
|
|
|
|
|
- name: Elastic GPG key is installed
|
|
|
|
copy:
|
|
|
|
src: elastic.asc
|
|
|
|
dest: /etc/apt/trusted.gpg.d/elastic.asc
|
|
|
|
force: yes
|
|
|
|
mode: "0644"
|
2018-06-28 18:10:28 +02:00
|
|
|
tags:
|
2021-05-06 10:42:12 +02:00
|
|
|
- metricbeat
|
|
|
|
- packages
|
2018-06-28 18:10:28 +02:00
|
|
|
|
|
|
|
- name: Elastic sources list is available
|
|
|
|
apt_repository:
|
|
|
|
repo: "deb https://artifacts.elastic.co/packages/{{ elastic_stack_version | mandatory }}/apt stable main"
|
|
|
|
filename: elastic
|
|
|
|
state: present
|
|
|
|
update_cache: yes
|
|
|
|
tags:
|
2021-05-06 10:42:12 +02:00
|
|
|
- metricbeat
|
|
|
|
- packages
|
2018-06-28 18:10:28 +02:00
|
|
|
|
|
|
|
- name: Metricbeat is installed
|
|
|
|
apt:
|
|
|
|
name: metricbeat
|
2021-02-16 16:35:25 +01:00
|
|
|
state: "{% if metribeat_upgrade_package %}latest{% else %}present{% endif %}"
|
|
|
|
notify: restart metricbeat
|
2018-06-28 18:10:28 +02:00
|
|
|
tags:
|
2021-02-16 16:35:25 +01:00
|
|
|
- metricbeat
|
|
|
|
- packages
|
2018-06-28 18:10:28 +02:00
|
|
|
|
|
|
|
- name: Metricbeat service is enabled
|
|
|
|
systemd:
|
|
|
|
name: metricbeat
|
|
|
|
enabled: yes
|
2021-02-16 16:35:25 +01:00
|
|
|
notify: restart metricbeat
|
2018-08-30 13:47:48 +02:00
|
|
|
|
2020-08-18 14:01:09 +02:00
|
|
|
# When we don't use a config template (default)
|
|
|
|
- block:
|
|
|
|
- name: Metricbeat knows where to find Elasticsearch
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
|
|
regexp: '^ hosts: .*'
|
|
|
|
line: " hosts: [\"{{ metricbeat_elasticsearch_hosts | join('\", \"') }}\"]"
|
|
|
|
insertafter: "output.elasticsearch:"
|
|
|
|
notify: restart metricbeat
|
2021-05-09 23:06:42 +02:00
|
|
|
when: metricbeat_elasticsearch_hosts | length > 0
|
2018-08-30 13:47:48 +02:00
|
|
|
|
2020-08-18 14:01:09 +02:00
|
|
|
- name: Metricbeat protocol for Elasticsearch
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
|
|
regexp: '^ #?protocol: .*'
|
|
|
|
line: " protocol: \"{{ metricbeat_elasticsearch_protocol }}\""
|
|
|
|
insertafter: "output.elasticsearch:"
|
|
|
|
notify: restart metricbeat
|
|
|
|
when: metricbeat_elasticsearch_protocol == "http" or metricbeat_elasticsearch_protocol == "https"
|
2019-01-08 11:05:20 +01:00
|
|
|
|
2020-08-18 14:01:09 +02:00
|
|
|
- name: Metricbeat auth/username for Elasticsearch are configured
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
|
|
regexp: '{{ item.regexp }}'
|
|
|
|
line: '{{ item.line }}'
|
|
|
|
insertafter: "output.elasticsearch:"
|
2021-05-04 14:18:40 +02:00
|
|
|
loop:
|
2020-08-18 14:01:09 +02:00
|
|
|
- { regexp: '^ #?username: .*', line: ' username: "{{ metricbeat_elasticsearch_auth_username }}"' }
|
|
|
|
- { regexp: '^ #?password: .*', line: ' password: "{{ metricbeat_elasticsearch_auth_password }}"' }
|
|
|
|
notify: restart metricbeat
|
|
|
|
when:
|
2021-05-09 23:06:42 +02:00
|
|
|
- metricbeat_elasticsearch_auth_username | length > 0
|
|
|
|
- metricbeat_elasticsearch_auth_password | length > 0
|
2019-01-29 17:04:36 +01:00
|
|
|
|
2020-08-18 14:01:09 +02:00
|
|
|
- name: Metricbeat api_key for Elasticsearch are configured
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
|
|
regexp: '^ #?api_key: .*'
|
|
|
|
line: ' api_key: "{{ metricbeat_elasticsearch_auth_api_key }}"'
|
|
|
|
insertafter: "output.elasticsearch:"
|
|
|
|
notify: restart metricbeat
|
2021-05-09 23:06:42 +02:00
|
|
|
when: metricbeat_elasticsearch_auth_api_key | length > 0
|
2019-01-29 17:04:36 +01:00
|
|
|
|
2020-08-18 14:01:09 +02:00
|
|
|
- name: disable cloud_metadata
|
|
|
|
replace:
|
|
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
|
|
regexp: '^(\s+)(- add_cloud_metadata:)'
|
|
|
|
replace: '\1# \2'
|
|
|
|
notify: restart metricbeat
|
2021-05-09 23:06:42 +02:00
|
|
|
when: not (metricbeat_processors_cloud_metadata | bool)
|
2020-08-18 14:01:09 +02:00
|
|
|
|
|
|
|
- name: cloud_metadata processor is disabled
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
|
|
line: " - add_cloud_metadata: ~"
|
|
|
|
insert_after: '^processors:'
|
|
|
|
notify: restart metricbeat
|
2021-05-09 23:06:42 +02:00
|
|
|
when: metricbeat_processors_cloud_metadata | bool
|
|
|
|
when: not (metricbeat_use_config_template | bool)
|
2020-08-18 14:01:09 +02:00
|
|
|
|
|
|
|
# When we use a config template
|
|
|
|
- block:
|
|
|
|
- name: Configuration is up-to-date
|
|
|
|
template:
|
|
|
|
src: "{{ item }}"
|
|
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
|
|
force: "{{ metricbeat_force_config }}"
|
2021-05-04 13:39:47 +02:00
|
|
|
loop: "{{ query('first_found', templates) }}"
|
|
|
|
vars:
|
|
|
|
templates:
|
2020-08-18 14:01:09 +02:00
|
|
|
- "templates/metricbeat/metricbeat.{{ inventory_hostname }}.yml.j2"
|
2021-05-19 14:35:08 +02:00
|
|
|
- "templates/metricbeat/metricbeat.{{ host_group | default('all') }}.yml.j2"
|
2020-08-18 14:01:09 +02:00
|
|
|
- "templates/metricbeat/metricbeat.default.yml.j2"
|
2021-05-04 13:39:47 +02:00
|
|
|
- "templates/metricbeat.default.yml.j2"
|
2020-08-18 14:01:09 +02:00
|
|
|
notify: restart metricbeat
|
2021-05-09 23:06:42 +02:00
|
|
|
when: metricbeat_update_config | bool
|
|
|
|
when: metricbeat_use_config_template | bool
|