forked from evolix/ansible-roles
91 lines
2.5 KiB
YAML
91 lines
2.5 KiB
YAML
---
|
|
|
|
- name: APT https transport is enabled
|
|
apt:
|
|
name: apt-transport-https
|
|
state: present
|
|
tags:
|
|
- metricbeat
|
|
- packages
|
|
|
|
- name: Elastic GPG key is installed
|
|
apt_key:
|
|
# url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
|
|
data: "{{ lookup('file', 'elasticsearch.key') }}"
|
|
state: present
|
|
tags:
|
|
- metricbeat
|
|
- packages
|
|
|
|
- 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:
|
|
- metricbeat
|
|
- packages
|
|
|
|
- name: Metricbeat is installed
|
|
apt:
|
|
name: metricbeat
|
|
state: present
|
|
tags:
|
|
- metricbeat
|
|
- packages
|
|
|
|
- name: Metricbeat service is enabled
|
|
systemd:
|
|
name: metricbeat
|
|
enabled: yes
|
|
|
|
- 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
|
|
when:
|
|
- metricbeat_elasticsearch_hosts
|
|
|
|
- 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"
|
|
|
|
- name: Metricbeat auth/username for Elasticsearch are configured
|
|
lineinfile:
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
regexp: '{{ item.regexp }}'
|
|
line: '{{ item.line }}'
|
|
insertafter: "output.elasticsearch:"
|
|
with_items:
|
|
- { regexp: '^ #?username: .*', line: ' username: "{{ metricbeat_elasticsearch_auth_username }}"' }
|
|
- { regexp: '^ #?password: .*', line: ' password: "{{ metricbeat_elasticsearch_auth_password }}"' }
|
|
notify: restart metricbeat
|
|
when:
|
|
- metricbeat_elasticsearch_auth_username != ""
|
|
- metricbeat_elasticsearch_auth_password != ""
|
|
|
|
- name: disable cloud_metadata
|
|
replace:
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
regexp: '^(\s+)(- add_cloud_metadata:)'
|
|
replace: '\1# \2'
|
|
notify: restart metricbeat
|
|
when: not metricbeat_processors_cloud_metadata
|
|
|
|
- name: cloud_metadata processor is disabled
|
|
lineinfile:
|
|
dest: /etc/metricbeat/metricbeat.yml
|
|
line: " - add_cloud_metadata: ~"
|
|
insert_after: '^processors:'
|
|
notify: restart metricbeat
|
|
when: metricbeat_processors_cloud_metadata
|