Skip to content

Instantly share code, notes, and snippets.

@t0mk
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t0mk/d49f59b05a926f51014a to your computer and use it in GitHub Desktop.
Save t0mk/d49f59b05a926f51014a to your computer and use it in GitHub Desktop.
Ansible Helsinki meetup 2014-10-29

Demo: To launch a few Docker containers on a virtual machine

Why: I want to have some containers running for playing with (..) (running Docker container on a VM is not the most efficient way to go, but for development it's alright)

To start with: vanilla instance of newest Ubuntu 14.04 cloud image

I use OpenStack. You can get one for free on Amazon. Probably also free tier in Rack, Euca ,...

sudo-capable SSH user, with my key in .ssh/authorized_keys

^ you get in any IaaS environment

The node must be in inventory, and Ansible must be able to reach it: ansible -m ping docker1. If your inventory is not so smart, you would use IP address.

I use nova inventory. Show output.

To install docker daemon and kernel extensions without reading any docs and without connecting to the machine

(This could be done w/ CoreOS, but CoreOS doesn't have Python, so no Ansible out of the box.)

a cool role in galaxy as docker.ubuntu: https://github.com/angstwad/docker.ubuntu

It takes care of docker installation.

The normal way: get the role, write playbook applying the role in the node.

My way: ansible-apply-role-to-host -r https://github.com/angstwad/docker.ubuntu docker1

Launch three containers with Ansible

There is a Docker module for Ansible: http://docs.ansible.com/docker_module.html

I prepared a simple role: https://github.com/t0mk/dockerdemo

Show cloned tree, and tasks/main.yml

It runs the training Flask app (image training/webapp) in each container and maps to ports 800{1,2,3} of the Docker host. The app just replies with "Hello world !"

again: ansible-apply-role-to-host -r https://github.com/t0mk/dockerdemo docker1

curl <host>:800{1,2,3}

Summary

  • With Ansible it's super-simple to get code from the Internet and immediately test it. It will not work on the first try but most likely on the second. I misse d this when working with Puppet.
  • Simple to handle docker containers with Ansible.
  • I did not SSH anywhere.
  • I did not upload or download anything.

Links

@jarilammi
Copy link

Would You recommend just for getting more familiar with Ansible the AWS Free Tier or just a plain local virtual machine?

@t0mk
Copy link
Author

t0mk commented Oct 30, 2014

Hi, if you just want to try Ansible out, I would recommend plain Vagrant and VirtualBox.

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