ad2d96d890
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend
|:-:|:-:|:-:|:-:|:-:
|2781|7|2774|4|:-1:
Reference build: <a href="https://jenkins.evolix.org/job/gitea/job/ansible-roles/job/unstable/248//ansiblelint">Evolix » ansible-roles » unstable #248</a>
gitea/ansible-roles/pipeline/head This commit looks good
133 lines
4.4 KiB
YAML
133 lines
4.4 KiB
YAML
---
|
|
- name: APT sources
|
|
ansible.builtin.include_tasks: apt_sources.yml
|
|
args:
|
|
apply:
|
|
tags:
|
|
- filebeat
|
|
- packages
|
|
|
|
- name: Filebeat is installed
|
|
ansible.builtin.apt:
|
|
name: filebeat
|
|
state: "{% if filebeat_upgrade_package %}latest{% else %}present{% endif %}"
|
|
notify: restart filebeat
|
|
tags:
|
|
- filebeat
|
|
- packages
|
|
|
|
- name: Filebeat service is enabled
|
|
ansible.builtin.systemd:
|
|
name: filebeat
|
|
enabled: yes
|
|
notify: restart filebeat
|
|
when: not ansible_check_mode
|
|
|
|
- name: is logstash-plugin available?
|
|
ansible.builtin.stat:
|
|
path: /usr/share/logstash/bin/logstash-plugin
|
|
check_mode: no
|
|
register: logstash_plugin
|
|
|
|
- name: is logstash-input-beats installed?
|
|
ansible.builtin.command:
|
|
cmd: grep logstash-input-beats /usr/share/logstash/Gemfile
|
|
check_mode: no
|
|
register: logstash_plugin_installed
|
|
failed_when: False
|
|
changed_when: False
|
|
when:
|
|
- filebeat_logstash_plugin | bool
|
|
- logstash_plugin.stat.exists
|
|
|
|
- name: Logstash plugin is installed
|
|
block:
|
|
- ansible.builtin.include_role:
|
|
name: evolix/remount-usr
|
|
|
|
- name: logstash-plugin install logstash-input-beats
|
|
ansible.builtin.command: /usr/share/logstash/bin/logstash-plugin install logstash-input-beats
|
|
when:
|
|
- filebeat_logstash_plugin | bool
|
|
- logstash_plugin.stat.exists
|
|
- not (logstash_plugin_installed | success)
|
|
|
|
# When we don't use a config template (default)
|
|
- block:
|
|
- name: cloud_metadata processor is disabled
|
|
ansible.builtin.replace:
|
|
dest: /etc/filebeat/filebeat.yml
|
|
regexp: '^(\s+)(- add_cloud_metadata:)'
|
|
replace: '\1# \2'
|
|
notify: restart filebeat
|
|
when: not (filebeat_processors_cloud_metadata | bool)
|
|
|
|
- name: cloud_metadata processor is disabled
|
|
ansible.builtin.lineinfile:
|
|
dest: /etc/filebeat/filebeat.yml
|
|
line: " - add_cloud_metadata: ~"
|
|
insert_after: '^processors:'
|
|
notify: restart filebeat
|
|
when: filebeat_processors_cloud_metadata | bool
|
|
|
|
- name: Filebeat knows where to find Elasticsearch
|
|
ansible.builtin.lineinfile:
|
|
dest: /etc/filebeat/filebeat.yml
|
|
regexp: '^ hosts: .*'
|
|
line: " hosts: [\"{{ filebeat_elasticsearch_hosts | join('\", \"') }}\"]"
|
|
insertafter: "output.elasticsearch:"
|
|
notify: restart filebeat
|
|
when: filebeat_elasticsearch_hosts | length > 0
|
|
|
|
- name: Filebeat protocol for Elasticsearch
|
|
ansible.builtin.lineinfile:
|
|
dest: /etc/filebeat/filebeat.yml
|
|
regexp: '^ #?protocol: .*'
|
|
line: " protocol: \"{{ filebeat_elasticsearch_protocol }}\""
|
|
insertafter: "output.elasticsearch:"
|
|
notify: restart filebeat
|
|
when: filebeat_elasticsearch_protocol == "http" or filebeat_elasticsearch_protocol == "https"
|
|
|
|
- name: Filebeat auth/username for Elasticsearch are configured
|
|
ansible.builtin.lineinfile:
|
|
dest: /etc/filebeat/filebeat.yml
|
|
regexp: '{{ item.regexp }}'
|
|
line: '{{ item.line }}'
|
|
insertafter: "output.elasticsearch:"
|
|
loop:
|
|
- { regexp: '^ #?username: .*', line: ' username: "{{ filebeat_elasticsearch_auth_username }}"' }
|
|
- { regexp: '^ #?password: .*', line: ' password: "{{ filebeat_elasticsearch_auth_password }}"' }
|
|
notify: restart filebeat
|
|
when:
|
|
- filebeat_elasticsearch_auth_username | length > 0
|
|
- filebeat_elasticsearch_auth_password | length > 0
|
|
when:
|
|
- not (filebeat_use_config_template | bool)
|
|
- not ansible_check_mode
|
|
|
|
- name: Filebeat api_key for Elasticsearch are configured
|
|
ansible.builtin.lineinfile:
|
|
dest: /etc/filebeat/filebeat.yml
|
|
regexp: '^ #?api_key: .*'
|
|
line: ' api_key: "{{ filebeat_elasticsearch_auth_api_key }}"'
|
|
insertafter: "output.elasticsearch:"
|
|
notify: restart filebeat
|
|
when: filebeat_elasticsearch_auth_api_key | length > 0
|
|
|
|
# When we use a config template
|
|
- block:
|
|
- name: Configuration is up-to-date
|
|
ansible.builtin.template:
|
|
src: "{{ item }}"
|
|
dest: /etc/filebeat/filebeat.yml
|
|
force: "{{ filebeat_force_config }}"
|
|
loop: "{{ query('first_found', templates) }}"
|
|
vars:
|
|
templates:
|
|
- "templates/filebeat/filebeat.{{ inventory_hostname }}.yml.j2"
|
|
- "templates/filebeat/filebeat.{{ host_group | default('all') }}.yml.j2"
|
|
- "templates/filebeat/filebeat.default.yml.j2"
|
|
- "templates/filebeat.default.yml.j2"
|
|
notify: restart filebeat
|
|
when: filebeat_update_config | bool
|
|
when: filebeat_use_config_template | bool
|