wazuh-ansible-4.8.1/roles/elastic-stack/ansible-elasticsearch/tasks/main.yml
2019-06-28 15:20:14 +02:00

170 lines
4.7 KiB
YAML

---
- import_tasks: RedHat.yml
when: ansible_os_family == 'RedHat'
- import_tasks: Debian.yml
when: ansible_os_family == "Debian"
- name: Create elasticsearch.service.d folder.
file: path=/etc/systemd/system/elasticsearch.service.d/ state=directory
when:
- ansible_service_mgr == "systemd"
- name: Configure Elasticsearch System Resources.
template:
src: elasticsearch_systemd.conf.j2
dest: /etc/systemd/system/elasticsearch.service.d/elasticsearch.conf
owner: root
group: elasticsearch
mode: 0660
notify: restart elasticsearch
tags: configure
when:
- ansible_service_mgr == "systemd"
- name: Debian/Ubuntu | Configure Elasticsearch System Resources.
template:
src: elasticsearch_nonsystemd.j2
dest: /etc/default/elasticsearch
owner: root
group: elasticsearch
mode: 0660
notify: restart elasticsearch
tags: configure
when:
- ansible_service_mgr != "systemd"
- ansible_os_family == "Debian"
- name: RedHat/CentOS/Fedora | Configure Elasticsearch System Resources.
template:
src: elasticsearch_nonsystemd.j2
dest: /etc/sysconfig/elasticsearch
owner: root
group: elasticsearch
mode: 0660
notify: restart elasticsearch
tags: configure
when:
- ansible_service_mgr != "systemd"
- ansible_os_family == "RedHat"
- name: Configure Elasticsearch.
template:
src: elasticsearch.yml.j2
dest: /etc/elasticsearch/elasticsearch.yml
owner: root
group: elasticsearch
mode: 0660
notify: restart elasticsearch
tags: configure
- name: Configure Elasticsearch JVM memmory.
template:
src: jvm.options.j2
dest: /etc/elasticsearch/jvm.options
owner: root
group: elasticsearch
mode: 0660
notify: restart elasticsearch
tags: configure
# fix in new PR (ignore_errors)
- name: Reload systemd
systemd: daemon_reload=true
ignore_errors: true
when:
- not (ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA")
- not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('15.04', '<'))
- not (ansible_distribution == "Debian" and ansible_distribution_version is version('8', '<'))
- name: Ensure Elasticsearch started and enabled
ignore_errors: true
service:
name: elasticsearch
enabled: true
state: started
- name: Make sure Elasticsearch is running before proceeding
wait_for: host={{ elasticsearch_network_host }} port={{ elasticsearch_http_port }} delay=3 timeout=300
tags:
- configure
- init
- name: Check for Wazuh Alerts template
uri:
url: "http://{{elasticsearch_network_host}}:{{elasticsearch_http_port}}/_template/wazuh"
method: GET
status_code: 200, 404
when: not elasticsearch_bootstrap_node or single_node
poll: 30
register: wazuh_alerts_template_exits
tags: init
- name: Installing Wazuh Alerts template
uri:
url: "http://{{elasticsearch_network_host}}:{{elasticsearch_http_port}}/_template/wazuh"
method: PUT
status_code: 200
body_format: json
body: "{{ lookup('template','wazuh-elastic7-template-alerts.json.j2') }}"
when:
- wazuh_alerts_template_exits.status is defined
- wazuh_alerts_template_exits.status != 200
tags: init
- name: Check that the instances.yml file exists
stat:
path: /usr/share/elasticsearch/instances.yml
register: instances_file_exists
when:
- node_generate_certs
- elasticsearch_xpack_security
- name: Write the instances.yml file in the selected node
template:
src: instances.yml.j2
dest: "/usr/share/elasticsearch/instances.yml"
tags:
- config
- xpack-security
when:
- node_generate_certs
- elasticsearch_xpack_security
- name: Check that the certificates ZIP file exists
stat:
path: /usr/share/elasticsearch/certs.zip
register: xpack_certs_zip
when:
- node_generate_certs
- elasticsearch_xpack_security
- name: Generating certificates for Elasticsearch security
shell: "/usr/share/elasticsearch/bin/elasticsearch-certutil cert ca --pem --in /usr/share/elasticsearch/instances.yml --out /usr/share/elasticsearch/certs.zip"
when:
- node_generate_certs
- instances_file_exists
- elasticsearch_xpack_security
- not xpack_certs_zip
tags: xpack-security
# - name: Importing certificates generated previously
# synchronize:
# mode: push
# src: /usr/share/elasticsearch/certs.zip
# dest: /usr/share/elasticsearch/certs.zip
# rsync_opts:
# - "--rsync-path='sudo rsync'"
# - "-v"
# delegate_to: "{{groups['elk'][0]}}"
# when:
# - not node_generate_certs
# - elasticsearch_xpack_security
# tags: xpack-security
- import_tasks: "RMRedHat.yml"
when: ansible_os_family == "RedHat"
- import_tasks: "RMDebian.yml"
when: ansible_os_family == "Debian"