Deploying Elastic Stack With Ansible Playbook
As a devops consultant, I have worked with ansible
quite a bit. Following the principles of infrastructure as code and with the motivation to automate as much infrastructure work as possible, many of our configuration are automated and manage as normal code, we commit them with git
and even run yaml syntax check in our ci/cd pipeline.
One of the configuration scripts I did was for automating the configuration of the elastic stack.
This script is availabe at my github repo, https://github.com/Misterhex/ansible-elk
This script configure:
- elasticsearch cluster with N number of nodes.
- kibana
- curator
- metricbeats on all compute nodes.
- import default dashboard for metricbeat
Below is the main playbook file site.yml
Concepts
Playbook contains plays
that will run when executed, plays
maps to inventory
. Plays
contains Roles
. Roles
are basically recommended encapsulation of a series of steps
that invoke ansible modules
. Modules
are built-in idempontent functions that configure the target servers. Servers are grouped and defined in inventories
, they are defined in an inventory file
.
Below is an example inventory file:
Running the playbook
To run the playbook, it is as simple as:
ansible-playbook -i inventory-sample site.yml
Conclusion
In conclusion, ansible is a simple yet awesome tools for automating configuration of softwares/services. Get started with installation here.