Commit 2b9a251b authored by Jürgen Haas's avatar Jürgen Haas

ansible-playbooks/general#85 Linting

parent 811fe4a0
elasticsearch:
purge:
- index: 'logstash'
- index: logstash
retention: 60
mode: 'daily'
- index: 'haproxy'
mode: daily
- index: haproxy
retention: 60
mode: 'single'
mode: single
......@@ -71,7 +71,7 @@ def purgeDaily(cat, day):
range = prefix + day.strftime('%Y.%m.%d')
for index in cat:
if index['index'].find(prefix) == 0 and index['index'] < range:
print(' Index: ' + index['index'])
print(' Index: + index['index])
buffer = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, 'localhost:9200/' + index['index'])
......
---
# file: roles/elasticsearch/handlers/main.yml
- name: "Add Elasticsearch to Boot-List"
- name: Add Elasticsearch to Boot-List
systemd:
name='elasticsearch'
state='started'
daemon_reload=yes
enabled=yes
- name: "Start Elasticsearch"
- name: Start Elasticsearch
service:
name='elasticsearch'
state='started'
- name: "Restart Elasticsearch"
- name: Restart Elasticsearch
service:
name='elasticsearch'
state='restarted'
---
# file: roles/elasticsearch/tasks/index.yml
- name: "Check Index"
- name: Check Index
uri:
url: 'http://localhost:9200/{{ index }}'
method: 'HEAD'
url: http://localhost:9200/{{ index }}
method: HEAD
register: es_index
failed_when: false
- name: "Create Index"
- name: Create Index
uri:
url: 'http://localhost:9200/{{ index }}'
method: 'PUT'
url: http://localhost:9200/{{ index }}
method: PUT
status_code: 200
when: es_index.status != 200
failed_when: false
- name: "Update Mapping"
- name: Update Mapping
uri:
url: 'http://localhost:9200/{{ index }}/_mapping/{{ index }}'
method: 'PUT'
url: http://localhost:9200/{{ index }}/_mapping/{{ index }}
method: PUT
body: '{{ lookup("file", "{{ index }}.json") }}'
status_code: 200
body_format: 'json'
body_format: json
failed_when: false
---
# file: roles/elasticsearch/tasks/install.yml
- name: "Apt Key"
- name: Apt Key
apt_key:
url: 'https://artifacts.elastic.co/GPG-KEY-elasticsearch'
state: 'present'
url: https://artifacts.elastic.co/GPG-KEY-elasticsearch
state: present
- name: "Apt Repository"
- name: Apt Repository
apt_repository:
repo: 'deb https://artifacts.elastic.co/packages/7.x/apt stable main'
state: 'present'
mode: '644'
repo: deb https://artifacts.elastic.co/packages/7.x/apt stable main
state: present
mode: 644
notify:
- "Add Elasticsearch to Boot-List"
- name: "Install Elasticsearch"
- name: Install Elasticsearch
apt:
pkg: 'elasticsearch'
state: 'present'
pkg: elasticsearch
state: present
update_cache: yes
- name: "Set default values"
- name: Set default values
template:
src: 'etc_default_elasticsearch'
dest: '/etc/default/elasticsearch'
owner: 'root'
group: 'elasticsearch'
mode: '644'
src: etc_default_elasticsearch
dest: /etc/default/elasticsearch
owner: root
group: elasticsearch
mode: 644
- name: "Install Plugins"
- name: Install Plugins
elasticsearch_plugin:
name: '{{ item }}'
state: 'present'
state: present
force: yes
with_items:
- 'ingest-attachment'
- ingest-attachment
notify:
- "Restart Elasticsearch"
- name: "Start Elasticsearch"
- name: Start Elasticsearch
service:
name: 'elasticsearch'
state: 'started'
name: elasticsearch
state: started
- name: "Wait until it is available"
- name: Wait until it is available
wait_for:
port: 9200
delay: 10
......
---
# file: roles/elasticsearch/tasks/main.yml
- name: "ElasticSearch Role"
set_fact: role_elasticsearch_started=true
tags: 'always'
- name: ElasticSearch Role
set_fact:
role_elasticsearch_started: yes
tags:
- always
- block:
......@@ -11,13 +13,13 @@
- include_tasks: index.yml
with_items:
- 'haproxy'
- 'ansible'
- 'uptime'
- haproxy
- ansible
- uptime
loop_control:
loop_var: index
- import_tasks: purge.yml
- import_tasks: readonly.yml
when: '"elasticsearch" not in excluded_roles'
when: not excluded_roles or "elasticsearch" not in excluded_roles
---
# file: roles/elasticsearch/tasks/purge.yml
- name: "Ensure Python Components"
- name: Ensure Python Components
pip:
name: '{{ packages }}'
state: 'present'
state: present
vars:
packages:
- 'python-dateutil'
- python-dateutil
- name: "Copy script"
- name: Copy script
copy:
src: 'purge.py'
dest: '/usr/local/bin/elasticpurge.py'
mode: '0755'
tags: 'cron'
src: purge.py
dest: /usr/local/bin/elasticpurge.py
mode: 0755
tags:
- cron
- name: "Set Purge Crons"
- name: Set Purge Crons
cron:
name: 'Elasticsearch Purge {{ item.index }}'
hour: '0'
minute: '10'
job: '/usr/local/bin/elasticpurge.py {{ item.index }} {{ item.retention }} {{ item.mode }} >>/var/log/elasticsearch/purge.log 2>&1'
name: Elasticsearch Purge {{ item.index }}
hour: 0
minute: 10
job: /usr/local/bin/elasticpurge.py {{ item.index }} {{ item.retention }} {{ item.mode }} >>/var/log/elasticsearch/purge.log 2>&1
disabled: '{{ item.disabled|default(false) }}'
with_items: '{{ elasticsearch.purge }}'
tags: 'cron'
tags:
- cron
---
# file: roles/elasticsearch/tasks/readonly.yml
- name: "Copy script"
- name: Copy script
copy:
src: 'elasticsearch-remove-readonly'
dest: '/usr/local/bin/elasticsearch-remove-readonly'
mode: '0755'
tags: 'cron'
src: elasticsearch-remove-readonly
dest: /usr/local/bin/elasticsearch-remove-readonly
mode: 0755
tags:
- cron
- name: "Set Remove Readonly Crons"
- name: Set Remove Readonly Crons
cron:
name: 'Elasticsearch Remove Readonly'
hour: '5'
minute: '55'
job: '/usr/local/bin/elasticsearch-remove-readonly >>/var/log/elasticsearch/readonly.log 2>&1'
name: Elasticsearch Remove Readonly
hour: 5
minute: 55
job: /usr/local/bin/elasticsearch-remove-readonly >>/var/log/elasticsearch/readonly.log 2>&1
disabled: '{{ crons_disabled|default(false) }}'
tags: 'cron'
tags:
- cron
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment