Skip to content

Instantly share code, notes, and snippets.

@bcattle
Last active July 21, 2016 22:32
Show Gist options
  • Save bcattle/90e64fbe808b3409ec2f to your computer and use it in GitHub Desktop.
Save bcattle/90e64fbe808b3409ec2f to your computer and use it in GitHub Desktop.
Bootstrap script to setup Boot2Docker to be run from Ansible
#!/bin/bash
# boot2docker-setup.sh
# Bryan Cattle
# 6/2/2015
# Configures boot2docker to run ansible scripts
if [[ $(boot2docker status) != "running" ]]; then
echo "Starting Boot2Docker"
boot2docker up
else
echo "Boot2Docker is running"
fi
# Check to see if we need to install python
# We need to do this if boot2docker started, since
# it's run from a ramdisk.
boot2docker ssh "which /usr/bin/python" > /dev/null 2>&1
if (($? > 0)); then
echo "Installing Python"
if [[ ! -f python.tcz ]]; then
wget http://www.tinycorelinux.net/6.x/x86/tcz/python.tcz
fi
scp -i ~/.ssh/id_boot2docker -P 2022 python.tcz docker@localhost:~
boot2docker ssh "tce-load -i python.tcz && rm -f python.tcz"
VERSION=$(boot2docker ssh "python --version")
echo "Installed $VERSION"
else
VERSION=$(boot2docker ssh "python --version")
echo "$VERSION already installed"
fi
# Test Ansible
ansible local -i hosts.local -a "echo Ansible Works\!"
; The default SSH port for boot2docker is 2022
; This can be confirmed with
; $ boot2docker config 2>&1 | awk '/SSHPort/ {print $3}'
;
; -- http://stackoverflow.com/a/25561071/1161906
[local]
localhost ansible_ssh_port=2022 ansible_ssh_user=docker ansible_ssh_private_key_file=~/.ssh/id_boot2docker
@tenitski
Copy link

I couldn't get it to work with files downloaded from outside of boot2docker - tce would install them but not really install. In the end I downloaded python inside of boot2docker (tce-load -w python.tcz), copied files to host OS (look in /tmp/tce/optional) and then had them copied & installed as in the script above.
Most likely my boot2docker needed some specific type of packages, but i could not figure out which exactly so just let it do downloading for me. Ideally this should be automated but will do for now.

@mg03
Copy link

mg03 commented Mar 9, 2016

I install python via tce but still having issue.

Ansible version: 1.9.2

My inventory file:

[b2d]
localhost ansible_ssh_port=2022 ansible_ssh_user=docker ansible_ssh_private_key_file=~/.ssh/id_boot2docker ansible_python_interpreter=/usr/local/bin/python ansible_ssh_args="-F /dev/null"

command im running

ansible b2d -i inventory/localhost -a "echo Ansible Works!" -vvvv

Output

ESTABLISH CONNECTION FOR USER: docker
REMOTE_MODULE command echo Ansible Works!
EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/gardame/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=2022 -o IdentityFile="/Users/gardame/.ssh/id_boot2docker" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=docker -o ConnectTimeout=10 localhost /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1457506032.42-87298897245920 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1457506032.42-87298897245920 && echo $HOME/.ansible/tmp/ansible-tmp-1457506032.42-87298897245920'
PUT /var/folders/tk/40ntfp_91gl9zbvytjx7zwgd_8h2q9/T/tmpD30JU5 TO /home/docker/.ansible/tmp/ansible-tmp-1457506032.42-87298897245920/command
EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/gardame/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o Port=2022 -o IdentityFile="/Users/gardame/.ssh/id_boot2docker" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=docker -o ConnectTimeout=10 localhost /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/local/bin/python /home/docker/.ansible/tmp/ansible-tmp-1457506032.42-87298897245920/command; rm -rf /home/docker/.ansible/tmp/ansible-tmp-1457506032.42-87298897245920/ >/dev/null 2>&1'
localhost | FAILED >> {
"failed": true,
"msg": "/bin/sh: /usr/local/bin/python: not found\r\nOpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011\ndebug1: Reading configuration data /etc/ssh_config\r\ndebug1: /etc/ssh_config line 20: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 30222\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to localhost closed.\r\n",
"parsed": false
}

Any ideas will be appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment