# Help setting up ES with Ansible/Docker/Vagrant

**URL:** <https://discuss.elastic.co/t/help-setting-up-es-with-ansible-docker-vagrant/17683>\
**Category:** Elasticsearch\
**Created:** [May 23, 2014, 2:24am UTC](https://discuss.elastic.co/t/help-setting-up-es-with-ansible-docker-vagrant/17683 "2014-05-23T02:24:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![heisenberg](https://avatars.discourse-cdn.com/v4/letter/h/4da419/32.png) [@heisenberg](https://discuss.elastic.co/u/heisenberg)\
**Post date:** [May 23, 2014, 2:24am UTC](https://discuss.elastic.co/t/help-setting-up-es-with-ansible-docker-vagrant/17683/1 "2014-05-23T02:24:20Z")

</div>

I have set up 3 VMs for running elastic search using Vagrant, and ansible  
(w/docker)

In my Hosts file:

I added these lines to define the 3 VM's addresses:  
192.168.50.10 earth  
192.168.50.11 hiveholm  
192.168.50.12 moth

This just gives the private address of the VM a name

I use Vagrant to build and map 3 VM's on my Mac:

Vagrantfile:

# -_- mode: ruby -_-

# vi: set ft=ruby :

ROOT = File.dirname(File.absolute\_path( **FILE** ))

# Vagrantfile API/syntax version. Don't touch unless you know what you're

doing!  
VAGRANTFILE\_API\_VERSION = '2'

# Default env properties which can be overridden

# Example overrides:

# echo "ENV['PASSENGER\_DOCKER\_PATH'] ||=

'../../phusion/passenger-docker' " \>\> ~/.vagrant.d/Vagrantfile

# echo "ENV['BASE\_BOX\_URL'] ||=

'd:/dev/vm/vagrant/boxes/phusion/'" \>\> ~/.vagrant.d/Vagrantfile  
BASE\_BOX\_URL = ENV['BASE\_BOX\_URL'] ||  
'[https://oss-binaries.phusionpassenger.com/vagrant/boxes/](https://oss-binaries.phusionpassenger.com/vagrant/boxes/)'  
VAGRANT\_BOX\_URL = ENV['VAGRANT\_BOX\_URL'] || BASE\_BOX\_URL +  
'ubuntu-12.04.3-amd64-vbox.box'  
VMWARE\_BOX\_URL = ENV['VMWARE\_BOX\_URL'] || BASE\_BOX\_URL +  
'ubuntu-12.04.3-amd64-vmwarefusion.box'  
BASEIMAGE\_PATH = ENV['BASEIMAGE\_PATH'] || '.'  
PASSENGER1\_DOCKER\_PATH = ENV['PASSENGER1\_PATH'] || '../vm1'  
PASSENGER2\_DOCKER\_PATH = ENV['PASSENGER2\_PATH'] || '../vm2'  
PASSENGER3\_DOCKER\_PATH = ENV['PASSENGER3\_PATH'] || '../vm3'

DOCKERIZER\_PATH = ENV['DOCKERIZER\_PATH'] || '../dockerizer'

$script = \<\<SCRIPT  
wget -q -O - [https://get.docker.io/gpg](https://get.docker.io/gpg) | apt-key add -  
echo deb [http://get.docker.io/ubuntu](http://get.docker.io/ubuntu) docker main \>  
/etc/apt/sources.list.d/docker.list  
apt-get update -qq  
apt-get install -q -y --force-yes lxc-docker  
usermod -a -G docker vagrant  
docker version  
su - vagrant -c 'echo alias d=docker \>\> ~/.bash\_aliases'  
SCRIPT

class MyInstaller \< VagrantVbguest::Installers::Linux  
def install(opts=nil, &block)  
super  
communicate.sudo('ln -s  
/opt/VBoxGuestAdditions-\*/lib/VBoxGuestAdditions /usr/lib', opts, &block)  
end  
end

Vagrant.configure(VAGRANTFILE\_API\_VERSION) do |config|  
config.vbguest.installer = MyInstaller

config.vm.define :vm1 do |vm1\_config|

```
vm1_config.vm.box = 'phusion1-open-ubuntu-12.04-amd64'
vm1_config.vm.box_url = VAGRANT_BOX_URL
vm1_config.ssh.forward_agent = true

passenger_docker_path = File.absolute_path(PASSENGER1_DOCKER_PATH, ROOT)
if File.directory?(passenger_docker_path)
  vm1_config.vm.synced_folder passenger_docker_path, 

```

'/vagrant/passenger-docker'  
end

```
baseimage_path = File.absolute_path(BASEIMAGE_PATH, ROOT)
if File.directory?(baseimage_path)
  vm1_config.vm.synced_folder baseimage_path, 

```

"/vagrant/baseimage-docker"  
end

```
dockerizer_path = File.absolute_path(DOCKERIZER_PATH, ROOT)
if File.directory?(dockerizer_path)
  vm1_config.vm.synced_folder dockerizer_path, '/vagrant/dockerizer'
end

vm1_config.vm.provider :vmware_fusion do |f, override|
  override.vm.box_url = VMWARE_BOX_URL
  f.vmx['displayName'] = 'baseimage-docker'
end

if Dir.glob("#{File.dirname( __FILE__ )}/.vagrant/machines/default/*/id").

```

empty?  
vm1\_config.vm.provision :shell, :inline =\> $script  
end

```
vm1_config.vm.network "private_network", ip: "192.168.50.10"

```

end

config.vm.define :vm2 do |vm2\_config|

```
vm2_config.vm.box = 'phusion1-open-ubuntu-12.04-amd64'
vm2_config.vm.box_url = VAGRANT_BOX_URL
vm2_config.ssh.forward_agent = true

passenger_docker_path = File.absolute_path(PASSENGER2_DOCKER_PATH, ROOT)
if File.directory?(passenger_docker_path)
  vm2_config.vm.synced_folder passenger_docker_path, 

```

'/vagrant/passenger-docker'  
end

```
baseimage_path = File.absolute_path(BASEIMAGE_PATH, ROOT)
if File.directory?(baseimage_path)
  vm2_config.vm.synced_folder baseimage_path, 

```

"/vagrant/baseimage-docker"  
end  
dockerizer\_path = File.absolute\_path(DOCKERIZER\_PATH, ROOT)  
if File.directory?(dockerizer\_path)  
vm2\_config.vm.synced\_folder dockerizer\_path, '/vagrant/dockerizer'  
end

```
vm2_config.vm.provider :vmware_fusion do |f, override|
  override.vm.box_url = VMWARE_BOX_URL
  f.vmx['displayName'] = 'baseimage-docker'
end

if Dir.glob("#{File.dirname( __FILE__ )}/.vagrant/machines/default/*/id").

```

empty?  
vm2\_config.vm.provision :shell, :inline =\> $script  
end

```
vm2_config.vm.network "private_network", ip: "192.168.50.11"

```

end

config.vm.define :vm3 do |vm3\_config|

```
vm3_config.vm.box = 'phusion1-open-ubuntu-12.04-amd64'
vm3_config.vm.box_url = VAGRANT_BOX_URL
vm3_config.ssh.forward_agent = true

passenger_docker_path = File.absolute_path(PASSENGER3_DOCKER_PATH, ROOT)
if File.directory?(passenger_docker_path)
  vm3_config.vm.synced_folder passenger_docker_path, 

```

'/vagrant/passenger-docker'  
end

```
baseimage_path = File.absolute_path(BASEIMAGE_PATH, ROOT)
if File.directory?(baseimage_path)
  vm3_config.vm.synced_folder baseimage_path, 

```

"/vagrant/baseimage-docker"  
end

```
dockerizer_path = File.absolute_path(DOCKERIZER_PATH, ROOT)
if File.directory?(dockerizer_path)
  vm3_config.vm.synced_folder dockerizer_path, '/vagrant/dockerizer'
end

vm3_config.vm.provider :vmware_fusion do |f, override|
  override.vm.box_url = VMWARE_BOX_URL
  f.vmx['displayName'] = 'baseimage-docker'
end

if Dir.glob("#{File.dirname( __FILE__ )}/.vagrant/machines/default/*/id").

```

empty?  
vm3\_config.vm.provision :shell, :inline =\> $script  
end

```
vm3_config.vm.network "private_network", ip: "192.168.50.12"

```

end

end

This builds and runs 3 VM's in a private network, using the phusion  
baseimage-docker base:  
I then run anansible playbook to setup the VM's so they have their own sash  
ansible-playbook (terra1.yml)

- name: terra  
hosts: all

# user: $user

remote\_user: root  
sudo: yes

gather\_facts: yes  
tasks:  
- name: install pip  
shell: apt-get -y install python-pip

```
- name: install docker-py
  pip: name=docker-py state=present

- name: Do the docker build
  shell: cd /vagrant/image && docker build -t traintracks_image_9 .

- name: Run the container
  docker: ports=45678:22,54328:54328,9200:9200,9201:9201,9202:9202,9300:

```

9300,9301:9301,9302:9302  
name=test\_traintracks\_image\_9g image=traintracks\_image\_9

Run using this command:

ansible-playbook terra1.yml -i hosts.ini -user=root --ask-pass -vvvv

this installs a couple of things and builds the base image inside the  
container with the build step and then runs it.  
(Note this is applied to all 3 VMs but in this testing I am just building  
out the first vm (earth))

Last step install and setup and run ElastciSearch:

I have reused the "the-ansibles" project playbook as a base for out  
playbook to setup and run elastic search  
Project is called traintracks  
ansible-playbook: terra\_es1.yml:

# file: terra\_es1.yml

- name: terra  
hosts: all

Run with this command:

ansible-playbook terra\_es1.yml -i terra1.ini -user=root -vvvv

installs and sets up all the required packages and finally installs elastic  
search

All these installation steps seem to SUCCEED or more correctly show no  
errors and we basically have not changed anything.  
But when you go into the docker container  
(ssh root@earth -p 45678)  
and look at the supervisord log and the elasticsearch log it shows this  
problem it shows this error:

[2014-05-22 10:15:57,306][INFO][node] [Apryll] version  
[0.90.5], pid[2456], build[c8714e8/2013-09-17T12:50:20Z]  
[2014-05-22 10:15:57,307][INFO][node] [Apryll]initializing  
...  
[2014-05-22 10:15:57,313][INFO][plugins] [Apryll] loaded  
[], sites []  
[2014-05-22 10:15:59,390][INFO][node] [Apryll]initialized  
[2014-05-22 10:15:59,390][INFO][node] [Apryll]starting  
...  
[2014-05-22 10:15:59,467][ERROR][bootstrap] [Apryll] {0.90.5  
}: Startup Failed ...

- BindTransportException[Failed to bind to [9300]]  
ChannelException[Failed to bind to: /192.168.50.10:9300]  
BindException[Cannot assign requested address]

I run netstat andit shows nothing is using the 9300 port but ES fails to  
bind it!

netstat -lc  
Active Internet connections (only servers)  
Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 82346d809c2f:domain _:_ LISTEN

tcp 0 0 \*:ssh _:_ LISTEN

tcp6 0 0 [::]:ssh [::]:\* LISTEN

udp 0 0 82346d809c2f:domain _:_

udp 0 0 82346d809c2f:ntp _:_

udp 0 0 localhost:ntp _:_

udp 0 0 \*:ntp _:_

udp6 0 0 fe80::34db:98ff:fe1:ntp [::]:\*

udp6 0 0 localhost:ntp [::]:\*

udp6 0 0 [::]:ntp [::]:\*

Active UNIX domain sockets (only servers)  
Proto RefCnt Flags Type State I-Node Path  
unix 2 [ACC] STREAM LISTENING 55239 @/tmp/fam-root-  
unix 2 [ACC] STREAM LISTENING 55224 /var/run/fail2ban  
/fail2ban.sock

This seems to indicate that nothing is using port 9300  
but I run the elastic search command from the command line inside the  
docker Container:

So I killed supervisord and ran the elasticsearch command from the ssh shell

/usr/local/etc/elasticsearch/bin/elasticsearch -f

I GET THIS:  
root@82346d809c2f:~# /usr/local/etc/elasticsearch/bin/elasticsearch -f  
[2014-05-22 10:42:03,447][INFO][node] [Fan Boy]version  
[0.90.5], pid[11886], build[c8714e8/2013-09-17T12:50:20Z]  
[2014-05-22 10:42:03,448][INFO][node] [Fan Boy]initializing  
...  
[2014-05-22 10:42:03,454][INFO][plugins] [Fan Boy]loaded  
[], sites []  
[2014-05-22 10:42:05,564][INFO][node] [Fan Boy]initialized  
[2014-05-22 10:42:05,564][INFO][node] [Fan Boy]starting  
...  
[2014-05-22 10:42:05,639][ERROR][bootstrap] [Fan Boy] {0.90.  
5}: Startup Failed ...

- BindTransportException[Failed to bind to [9300]]  
ChannelException[Failed to bind to: /192.168.50.10:9300]  
BindException[Cannot assign requested address]

But I dont get more information

Any help would be appreciated!

Jeff Wilson  
heisenberg@traintracks.io

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/53c94b26-94b1-4cfb-ba3f-892f1d4a1edf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/53c94b26-94b1-4cfb-ba3f-892f1d4a1edf%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:27am UTC](https://discuss.elastic.co/t/help-setting-up-es-with-ansible-docker-vagrant/17683/2 "2017-07-06T01:27:29Z")

</div>


