ansible-roles/logstash/tasks/main.yml
Mathieu Trossevin 7c632352a0
Replace the include module with include_tasks or import_tasks
The behaviour of the `include` module is badly defined (it try to choose
between statically importing the tasks and dynamically including them)
and can cause problems depending on any number of constraints (mostly if
it choose the wrong behaviour).

Replace it with the `import_tasks` (always statically import tasks) unless
the `include` is in a loop in which case we replace it with
`include_tasks` (always dynamically include tasks).
2023-01-03 14:43:42 +01:00

121 lines
2.5 KiB
YAML

---
- name: APT https transport is enabled
apt:
name: apt-transport-https
state: present
tags:
- logstash
- packages
- name: Look for legacy apt keyring
stat:
path: /etc/apt/trusted.gpg
register: _trusted_gpg_keyring
tags:
- logstash
- packages
- name: Elastic embedded GPG key is absent
apt_key:
id: "D88E42B4"
keyring: /etc/apt/trusted.gpg
state: absent
when: _trusted_gpg_keyring.stat.exists
tags:
- logstash
- packages
- name: Elastic GPG key is installed
copy:
src: elastic.asc
dest: "{{ apt_keyring_dir }}/elastic.asc"
force: yes
mode: "0644"
owner: root
group: root
tags:
- logstash
- packages
- name: Elastic sources list is available
apt_repository:
repo: "deb [signed-by={{ apt_keyring_dir }}/elastic.asc] https://artifacts.elastic.co/packages/{{ elastic_stack_version | mandatory }}/apt stable main"
filename: elastic
state: present
update_cache: yes
tags:
- logstash
- packages
- name: Unsigned Elastic sources list is not available
apt_repository:
repo: "deb https://artifacts.elastic.co/packages/{{ elastic_stack_version | mandatory }}/apt stable main"
filename: elastic
state: absent
update_cache: yes
tags:
- logstash
- packages
- name: Logstash is installed
apt:
name: logstash
state: present
tags:
- logstash
- packages
- name: Logstash service is enabled
systemd:
name: logstash
enabled: yes
tags:
- logstash
- name: JVM Heap size (min) is set
lineinfile:
dest: /etc/logstash/jvm.options
regexp: "^-Xms"
line: "-Xms{{ logstash_jvm_xms }}"
tags:
- logstash
- config
- name: JVM Heap size (max) is set
lineinfile:
dest: /etc/logstash/jvm.options
regexp: "^-Xmx"
line: "-Xmx{{ logstash_jvm_xmx }}"
tags:
- logstash
- config
- name: Add a configuration
template:
src: "{{ item }}"
dest: /etc/logstash/conf.d/logstash.conf
owner: logstash
group: logstash
mode: "0640"
force: "{{ logstash_config_force | bool }}"
loop: "{{ query('first_found', templates) }}"
vars:
templates:
- "templates/logstash/logstash.{{ inventory_hostname }}.conf.j2"
- "templates/logstash/logstash.{{ host_group | default('all') }}.conf.j2"
- "templates/logstash/logstash.default.conf.j2"
- "templates/logstash.default.conf.j2"
register: logstash_template
tags:
- logstash
- config
- debug:
var: logstash_template
verbosity: 1
- import_tasks: logs.yml
- import_tasks: tmpdir.yml