ELK stack deployment with Ansible
As human beings, we like to believe that each and every one of us is a special individual, and not easily replaceable. That may be fine, but please, don’t fall into the habit of treating your computer the same way.
Ansible is a free software platform for configuring and managing computers, and I’ve been using it a lot lately to manage the ELK stack. Elasticsearch, Logstash and Kibana.
I can define a list of servers I want to manage in a YAML config file – the so called inventory:
1 2 3 4 5 6 7 8 9 10 11 12 |
[elasticearch-master] es-master1.mydomain.com es-master2.mydomain.com es-master3.mydomain.com [elasticsearch-data] elk-data1.mydomain.com elk-data2.mydomain.com elk-data3.mydomain.com [kibana] kibana.mydomain.com |
And define the roles for the servers in another YAML config file – the so called playbook:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
- hosts: elasticsearch-master roles: - ansible-elasticsearch - hosts: elasticsearch-data roles: - ansible-elasticsearch - hosts: logstash roles: - ansible-logstash - hosts: kibana roles: - ansible-kibana |
Each group of servers may have their own files containing configuration variables.
1 2 3 |
elasticsearch_version: 2.1.0 elasticsearch_node_master: false elasticsearch_heap_size: 1000G |
Ansible is used for configuring the ELK stack vagrant box at https://github.com/comperiosearch/vagrant-elk-box-ansible, which was recently upgraded with Elasticsearch 2.1, Kibana 4.3 and Logstash 2.1
The same set of Ansible roles can be applied when the configuration needs to move into production, by applying another set of variable files with modified host names, certificates and such. The possible ways to do this are several.
How does it work?
Ansible is agent-less. This means, you do not install anything (an agent) on the machines you control. Ansible needs only to be installed on the controlling machine (Linux/OSX) and connects to the managed machines (some support for windows, even) using SSH. The only requirement on the managed machines is python.
Happy ansibling!