255 lines
6.7 KiB
YAML
255 lines
6.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: Install unzip dependency.
|
|
package:
|
|
name: unzip
|
|
state: present
|
|
delegate_to: "127.0.0.1"
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
|
|
|
|
- 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 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)
|
|
|
|
- import_tasks: "RMRedHat.yml"
|
|
when: ansible_os_family == "RedHat"
|
|
|
|
- name: Check if certificate exists locally
|
|
stat:
|
|
path: "{{ node_certs_destination }}/{{ elasticsearch_node_name }}.crt"
|
|
register: certificate_file_exists
|
|
when:
|
|
- elasticsearch_xpack_security
|
|
|
|
- name: Write the instances.yml file in the selected node (force = no)
|
|
template:
|
|
src: instances.yml.j2
|
|
dest: "{{ node_certs_source }}/instances.yml"
|
|
force: no
|
|
register: instances_file_exists
|
|
tags:
|
|
- config
|
|
- xpack-security
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
- not certificate_file_exists.stat.exists
|
|
|
|
- name: Update instances.yml status after generation
|
|
stat:
|
|
path: "{{ node_certs_source }}/instances.yml"
|
|
register: instances_file_exists
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
|
|
- name: Check if the certificates ZIP file exists
|
|
stat:
|
|
path: "{{ node_certs_source }}/certs.zip"
|
|
register: xpack_certs_zip
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
|
|
- name: Generating certificates for Elasticsearch security
|
|
command: >-
|
|
"/usr/share/elasticsearch/bin/elasticsearch-certutil cert ca --pem --in
|
|
{{ node_certs_source }}/instances.yml --out {{ node_certs_source }}/certs.zip"
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
- not xpack_certs_zip.stat.exists
|
|
- not certificate_file_exists.stat.exists
|
|
register: certs_file_generated
|
|
tags: xpack-security
|
|
|
|
- name: Create the certificates directory
|
|
file:
|
|
path: "{{master_certs_destination}}"
|
|
state: directory
|
|
mode: '0700'
|
|
delegate_to: "127.0.0.1"
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
|
|
- name: Copying certificates to Ansible master
|
|
fetch:
|
|
src: "{{node_certs_source}}/certs.zip"
|
|
dest: "{{master_certs_destination}}/"
|
|
flat: yes
|
|
mode: 0700
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
tags: xpack-security
|
|
|
|
- name: Delete certs.zip in Generator node
|
|
file:
|
|
state: absent
|
|
path: "{{ node_certs_source }}/certs.zip"
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
|
|
- name: Unzip generated certs.zip
|
|
unarchive:
|
|
src: "{{master_certs_destination}}/certs.zip"
|
|
dest: "{{master_certs_destination}}/"
|
|
become: true
|
|
delegate_to: "127.0.0.1"
|
|
when:
|
|
- node_certs_generator
|
|
- elasticsearch_xpack_security
|
|
tags: xpack-security
|
|
|
|
- name: Ensuring certificates folder owner
|
|
file:
|
|
path: "{{ node_certs_destination }}/"
|
|
state: directory
|
|
recurse: yes
|
|
owner: elasticsearch
|
|
group: elasticsearch
|
|
when:
|
|
- check_certs_permissions is defined
|
|
- elasticsearch_xpack_security
|
|
tags: xpack-security
|
|
|
|
- name: Ensuring certificates folder owner
|
|
file:
|
|
path: "{{ node_certs_destination }}/"
|
|
mode: '0770'
|
|
recurse: yes
|
|
when:
|
|
- check_certs_permissions is defined
|
|
- elasticsearch_xpack_security
|
|
tags: xpack-security
|
|
|
|
- name: Copying node's certificate from master
|
|
copy:
|
|
src: "{{item}}"
|
|
dest: "{{node_certs_destination}}/"
|
|
with_items:
|
|
- "{{master_certs_destination}}/{{elasticsearch_node_name}}/{{ elasticsearch_node_name }}.key"
|
|
- "{{master_certs_destination}}/{{elasticsearch_node_name}}/{{ elasticsearch_node_name }}.crt"
|
|
- "{{master_certs_destination}}/ca/ca.crt"
|
|
tags: xpack-security
|
|
|
|
- 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: Set elasticsearch bootstrap password
|
|
shell: |
|
|
set -o pipefail
|
|
"echo '{{ elasticsearch_xpack_security_password }}' | {{ node_certs_source }}/bin/elasticsearch-keystore add -xf 'bootstrap.password'"
|
|
when:
|
|
- elasticsearch_xpack_security
|
|
|
|
- name: Trusty | set MAX_LOCKED_MEMORY=unlimited in Elasticsearch in /etc/security/limits.conf
|
|
lineinfile:
|
|
path: /etc/security/limits.conf
|
|
line: elasticsearch - memlock unlimited
|
|
create: yes
|
|
become: true
|
|
when:
|
|
- ansible_distribution == "Ubuntu"
|
|
- ansible_distribution_major_version | int == 14
|
|
changed_when: false
|
|
|
|
- name: Trusty | set MAX_LOCKED_MEMORY=unlimited in Elasticsearch in /etc/security/limits.d/elasticsearch.conf
|
|
lineinfile:
|
|
path: /etc/security/limits.d/elasticsearch.conf
|
|
line: elasticsearch - memlock unlimited
|
|
create: yes
|
|
become: true
|
|
changed_when: false
|
|
when:
|
|
- ansible_distribution == "Ubuntu"
|
|
- ansible_distribution_major_version | int == 14
|
|
- name: Ensure Elasticsearch started and enabled
|
|
service:
|
|
name: elasticsearch
|
|
enabled: true
|
|
state: started
|
|
tags:
|
|
- configure
|
|
- init
|
|
|
|
- name: Make sure Elasticsearch is running before proceeding
|
|
wait_for: host={{ elasticsearch_network_host }} port={{ elasticsearch_http_port }} delay=3 timeout=400
|
|
tags:
|
|
- configure
|
|
- init
|
|
|
|
- import_tasks: "RMRedHat.yml"
|
|
when: ansible_os_family == "RedHat"
|
|
|
|
- import_tasks: "RMDebian.yml"
|
|
when: ansible_os_family == "Debian"
|