feat: split tasks

This commit is contained in:
Adrien Waksberg 2020-02-09 15:15:24 +01:00
parent c867790a8c
commit 033627595d
5 changed files with 82 additions and 77 deletions

21
tasks/config.yml Normal file
View file

@ -0,0 +1,21 @@
---
- name: set heap size
lineinfile:
path: /etc/elasticsearch/jvm.options
regexp: '^-{{ item }}'
line: '-{{ item }}{{ elasticsearch_heap_size }}'
loop:
- Xms
- Xmx
notify: restart elasticsearch
tags: elasticsearch
- name: copy config file
copy:
content: '{{ elasticsearch_full_config|to_yaml }}'
dest: /etc/elasticsearch/elasticsearch.yml
owner: root
group: elasticsearch
mode: 0640
notify: restart elasticsearch
tags: elasticsearch

11
tasks/data.yml Normal file
View file

@ -0,0 +1,11 @@
---
- name: copy index templates
elasticsearch_template:
name: '{{ item.key }}'
index_patterns: '{{ item.value.index_patterns }}'
settings: '{{ item.value.settings|default({}) }}'
mappings: '{{ item.value.mappings|default({}) }}'
no_log: true
loop: '{{ elasticsearch_index_templates|dict2items }}'
run_once: true
tags: elasticsearch

View file

@ -1,78 +1,5 @@
---
- name: install dependencies packages
apt:
name: '{{ packages }}'
vars:
packages:
- apt-transport-https
- python-requests
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: add repository key
apt_key:
url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: add repository
apt_repository:
repo: deb https://artifacts.elastic.co/packages/7.x/apt stable main
tags: elasticsearch
- name: install package
apt:
name: elasticsearch
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: set heap size
lineinfile:
path: /etc/elasticsearch/jvm.options
regexp: '^-{{ item }}'
line: '-{{ item }}{{ elasticsearch_heap_size }}'
loop:
- Xms
- Xmx
notify: restart elasticsearch
tags: elasticsearch
- name: copy config file
copy:
content: '{{ elasticsearch_full_config|to_yaml }}'
dest: /etc/elasticsearch/elasticsearch.yml
owner: root
group: elasticsearch
mode: 0640
notify: restart elasticsearch
tags: elasticsearch
- name: enable and start service
systemd:
name: elasticsearch
state: started
enabled: true
tags: elasticsearch
- name: wait for api is available
wait_for:
port: 9200
timeout: 10
tags: elasticsearch
- name: copy index templates
elasticsearch_template:
name: '{{ item.key }}'
index_patterns: '{{ item.value.index_patterns }}'
settings: '{{ item.value.settings|default({}) }}'
mappings: '{{ item.value.mappings|default({}) }}'
no_log: true
loop: '{{ elasticsearch_index_templates|dict2items }}'
run_once: true
tags: elasticsearch
- import_tasks: packages.yml
- import_tasks: config.yml
- import_tasks: service.yml
- import_tasks: data.yml

33
tasks/packages.yml Normal file
View file

@ -0,0 +1,33 @@
---
- name: install dependencies packages
apt:
name: '{{ packages }}'
vars:
packages:
- apt-transport-https
- python-requests
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: add repository key
apt_key:
url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
retries: 2
register: result
until: result is succeeded
tags: elasticsearch
- name: add repository
apt_repository:
repo: deb https://artifacts.elastic.co/packages/7.x/apt stable main
tags: elasticsearch
- name: install package
apt:
name: elasticsearch
retries: 2
register: result
until: result is succeeded
tags: elasticsearch

13
tasks/service.yml Normal file
View file

@ -0,0 +1,13 @@
---
- name: enable and start service
systemd:
name: elasticsearch
state: started
enabled: true
tags: elasticsearch
- name: wait for api is available
wait_for:
port: 9200
timeout: 10
tags: elasticsearch