Ansible playbook to spin up an Elasticsearch cluster on Amazon's EC2 platform
##Setup
- Amazon has a great walkthrough
- Port 9300 should only be open to rest of the security group (Elasticsearch Transport Layer)
- Port 9200 and/or Port 80 should be carefully restricted (Elasticsearch Command Layer)
- Port 22 should be open (SSH Access)
- You can only download this once, and instances are locked to a key, be careful!
- Use your package manager or download directly from Ansible
deploy_elasticsearch.yml
-
Insert your keypair name, instance type, security group, AMI image, and instance count
keypair: EC2KEYPAIRNAME
instance_type: t1.micro
security_group: EC2SECURITYGROUPNAME
image: AMINAME
instance_count: 2 -
I used ami-c30360aa (Ubuntu 13.04 64-bit), but other Ubuntu images should work.
elasticsearch/elasticsearch.yml
- Insert your AWS access key and secret key, and add any additional settings
##Run
-
Calling source on a shell script is great for this
>\#!/bin/bash >export AWS_ACCESS_KEY_ID='AKIA123456781234567' >export AWS_SECRET_ACCESS_KEY='123abcdefghijklmnopqrstuv'
-
Execute the following:
ansible-playbook deploy_elasticsearch.yml -vv --private-key=/path/to/ec2/key
-
Make sure the key has permissions for only the current user!
-
Or test your cluster by executing
curl http://EC2PUBLICIPOFANODE:9200/_cluster/health?pretty=true
####Quick fixes
- If Ansible complains about the local host group not existing, you may need to add 127.0.0.1 under the [local] heading in your ansible hosts file.