├── README.md ├── devel-centos7 └── Dockerfile ├── devel-ubuntu14.04 └── Dockerfile ├── examples ├── memcached-from-galaxy │ ├── Dockerfile │ └── site.yml └── webserver-simple │ ├── Dockerfile │ └── ansible │ ├── index.j2 │ └── site.yml ├── stable-centos7 └── Dockerfile └── stable-ubuntu14.04 └── Dockerfile /README.md: -------------------------------------------------------------------------------- 1 | THESE IMAGES HAVE BEEN DEPRECATED 2 | ================================= 3 | 4 | Ansible no longer maintains images in Dockerhub directly. There are 5 | several Ansible images on Dockerhub that are maintained by members of 6 | the Ansible community, which you can find with the [following search](https://hub.docker.com/search/?q=ansible&page=1&isAutomated=0&isOfficial=0&pullCount=1&starCount=0) 7 | 8 | 9 | Ansible-Docker-Base 10 | =================== 11 | 12 | These are base docker images that include Ansible. 13 | 14 | Ansible, Inc maintains these images so that people can easily build docker images from ansible playbooks. 15 | 16 | While Ansible modules can help you deploy container images (and also prepare host dependencies to be able to run containers), this document is about how to use ansible to efficiently describe and build them as well. 17 | 18 | Obtaining these Images from DockerHub 19 | ===================================== 20 | 21 | Ansible, Inc content on DockerHub lives at https://registry.hub.docker.com/u/ansible/ 22 | 23 | There are base images available currently for CentOS 7 and Ubuntu 14.04 LTS, using both the latest 24 | stable version of Ansible as well as development branch snapshots. 25 | 26 | Building Your Own Container Based on an Ansible Image 27 | ===================================================== 28 | 29 | By specifying a Dockerfile, it is easy to describe a container image primarily defined by an ansible-playbook, using a very minimal Dockerfile. 30 | 31 | Take a look at [this Dockerfile](https://github.com/ansible/ansible-docker-base/blob/master/examples/webserver-simple/Dockerfile) for a sample of what one looks like. 32 | 33 | To build this image, simply cd into the directory that contains the Dockerfile and run: 34 | 35 | docker build -t webserver_simple . 36 | 37 | This will produce an image tagged "webserver_simple" based on the Ansible playbook run. [Here's the playbook that defines the configuration](https://github.com/ansible/ansible-docker-base/blob/master/examples/webserver-simple/ansible/site.yml). 38 | 39 | Your own content will probably be kept in it's own git repos. You may wish to connect your repositories containing Ansible+Docker playbooks to DockerHub, to trigger automatic rebuilds of your container 40 | images when your underlying ansible playbooks, or the applications they might embed, change. 41 | 42 | Selecting Versions of Ansible 43 | ============================= 44 | 45 | The DockerFile shown above selected the latest CentOS tag of Ansible's Docker images. The first line of the DockerFile can be changed to select another base operating system or Ansible version should you wish to use a different OS or different Ansible version. 46 | 47 | The following options are available: 48 | 49 | FROM ansible/centos7-ansible:stable 50 | FROM ansible/centos7-ansible:devel 51 | FROM ansible/ubuntu14.04-ansible:stable 52 | FROM ansible/ubuntu14.04-ansible:devel 53 | 54 | Ansible images on DockerHub will be updated periodically. 55 | 56 | Jumping Docker Content with Ansible Galaxy 57 | ========================================== 58 | 59 | While Ansible provides 240+ modules for managing various aspects of IT components and is a great starting point for describing your applications, [Ansible Galaxy](http://galaxy.ansible.com) provides complete automation for deploying a very large number of popular apps and takes this to the next level. 60 | 61 | To use existing ansible-role content within Docker, simply switch into a playbook directory and download the roles. For example, to configure the ELK stack: 62 | 63 | mkdir roles/ 64 | cd roles/ 65 | ansible-galaxy install bakhti.elk 66 | 67 | And then leverage the role content in the playbook: 68 | 69 | - hosts: localhost 70 | roles: 71 | - bakhti.elk 72 | 73 | So, a 3 line playbook then brings up an entire ELK stack in a container image :) 74 | 75 | Deploying Your Ansible-Built Docker Containers with Ansible 76 | =========================================================== 77 | 78 | Once available on a registry, images can be deployed using the [Ansible Docker Module](http://docs.ansible.com/docker_module.html). This can be a lightweight 79 | way to specify what containers should run on which hosts. 80 | 81 | Here's a minimal example of running a Tomcat container on all of your hosts: 82 | 83 | - hosts: web 84 | sudo: yes 85 | tasks: 86 | - name: run tomcat servers 87 | docker: image=my-tomcat command="service tomcat6 start" ports=8080 88 | 89 | Replace the "image" parameter with the name of the image above in your registry. 90 | 91 | For more information, consult the [Ansible Docker module documentation](http://docs.ansible.com/docker_module.html) 92 | 93 | As your needs grow more detailed and you wish to specify different containers for different hosts, 94 | you might have a list called "run_containers" defined per Ansible host group, saying which containers to run on each host. This can allow ansible to be used as a lightweight cloud, all without any additional moving parts. 95 | 96 | Rebuilding Automatically when the Ansible Image Updates 97 | ======================================================= 98 | 99 | If you are using a Docker Hub automated build to build your images you can set 100 | your image to rebuild whenever the base ansible image (hosted by Ansible, Inc) is updated: 101 | 102 | 1. Go to the docker hub page for your repository. 103 | 2. In the sidebar labeled "Settings", find the entry marked "Repository Links" 104 | 3. On the "Repository Links" page, enter the Ansible repository you are layering 105 | your image on top of. For instance, if you are using the 106 | ubuntu14.04-ansible repository, enter ansible/ubuntu14.04-ansible 107 | into the "Repository Name" box and click "Add". 108 | 4. Docker hub will now automatically rebuild your image whenever that ansible 109 | repository has a new build. 110 | 111 | Questions? 112 | ========== 113 | 114 | If you'd like to talk about Ansible+Docker, stop by the [ansible-project mailing list](https://groups.google.com/forum/#!forum/ansible-project) or #ansible on irc.freenode.net for IRC. 115 | 116 | 117 | -------------------------------------------------------------------------------- /devel-centos7/Dockerfile: -------------------------------------------------------------------------------- 1 | # Latest version of centos 2 | FROM centos:centos7 3 | MAINTAINER Toshio Kuratomi 4 | RUN yum clean all && \ 5 | yum -y install epel-release && \ 6 | yum -y install PyYAML python-jinja2 python-httplib2 python-keyczar python-paramiko python-setuptools git python-pip 7 | RUN mkdir /etc/ansible/ 8 | RUN echo '[local]\nlocalhost\n' > /etc/ansible/hosts 9 | RUN mkdir /opt/ansible/ 10 | RUN git clone http://github.com/ansible/ansible.git /opt/ansible/ansible 11 | WORKDIR /opt/ansible/ansible 12 | RUN git submodule update --init 13 | ENV PATH /opt/ansible/ansible/bin:/bin:/usr/bin:/sbin:/usr/sbin 14 | ENV PYTHONPATH /opt/ansible/ansible/lib 15 | ENV ANSIBLE_LIBRARY /opt/ansible/ansible/library 16 | -------------------------------------------------------------------------------- /devel-ubuntu14.04/Dockerfile: -------------------------------------------------------------------------------- 1 | # Latest Ubuntu LTS 2 | FROM ubuntu:14.04 3 | MAINTAINER Toshio Kuratomi 4 | RUN apt-get -y update && \ 5 | apt-get install -y python-yaml python-jinja2 python-httplib2 python-keyczar python-paramiko python-setuptools python-pkg-resources git python-pip 6 | RUN mkdir /etc/ansible/ 7 | RUN echo '[local]\nlocalhost\n' > /etc/ansible/hosts 8 | RUN mkdir /opt/ansible/ 9 | RUN git clone http://github.com/ansible/ansible.git /opt/ansible/ansible 10 | WORKDIR /opt/ansible/ansible 11 | RUN git submodule update --init 12 | ENV PATH /opt/ansible/ansible/bin:/bin:/usr/bin:/sbin:/usr/sbin 13 | ENV PYTHONPATH /opt/ansible/ansible/lib 14 | ENV ANSIBLE_LIBRARY /opt/ansible/ansible/library 15 | -------------------------------------------------------------------------------- /examples/memcached-from-galaxy/Dockerfile: -------------------------------------------------------------------------------- 1 | #FROM ansible/centos7-ansible:stable 2 | FROM ansible/ubuntu14.04-ansible:stable 3 | 4 | 5 | # Retrieve your playbooks. Here we have them stored in a git repo 6 | RUN mkdir /srv/example 7 | WORKDIR /srv/example 8 | ADD site.yml /srv/example/ 9 | 10 | # For this one we're going to retrieve a prebuilt memcached role from 11 | # ansible-galaxy. This could be an easy way to evaluate a role or to quickly 12 | # get a service up and running in your infrastructure. 13 | RUN ansible-galaxy install geerlingguy.memcached 14 | 15 | # Bootstrapping is over, now run ansible on your playbook to finish configuring 16 | # your docker image. 17 | RUN ansible-playbook site.yml -c local 18 | 19 | # We can mix docker configuration of the container with ansible configuration 20 | # if we want to 21 | EXPOSE 11211 22 | 23 | # And then start up our service 24 | ENTRYPOINT ["/usr/bin/memcached", "-u", "memcache", "-l", "0.0.0.0", "-c", "1024", "-p", "11211"] 25 | -------------------------------------------------------------------------------- /examples/memcached-from-galaxy/site.yml: -------------------------------------------------------------------------------- 1 | - hosts: localhost 2 | roles: 3 | - role: geerlingguy.memcached 4 | -------------------------------------------------------------------------------- /examples/webserver-simple/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ansible/centos7-ansible:stable 2 | # or, for example, FROM ansible/ubuntu14.04-ansible:stable 3 | 4 | # Add playbooks to the Docker image 5 | ADD ansible /srv/example/ 6 | WORKDIR /srv/example 7 | 8 | # Run Ansible to configure the Docker image 9 | RUN ansible-playbook site.yml -c local 10 | 11 | # Other Dockerfile directives are still valid 12 | EXPOSE 22 3000 80 13 | ENTRYPOINT ["/usr/local/bin/apachectl", "-DFOREGROUND"] 14 | -------------------------------------------------------------------------------- /examples/webserver-simple/ansible/index.j2: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Created via Ansible Playbook 5 | 6 | 7 |

8 | {{ ansible_distribution }} {{ ansible_distribution_version }} web server configured by ansible. 9 |

10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/webserver-simple/ansible/site.yml: -------------------------------------------------------------------------------- 1 | - hosts: localhost 2 | 3 | vars: 4 | apache_group: 5 | Debian: "root" 6 | RedHat: "apache" 7 | apache_ctl: 8 | Debian: "/usr/sbin/apache2ctl" 9 | RedHat: "/usr/sbin/apachectl" 10 | 11 | tasks: 12 | - yum: pkg=httpd state=present 13 | when: ansible_os_family == "RedHat" 14 | 15 | - apt: update_cache=yes name="apache2" state=present 16 | when: ansible_os_family == "Debian" 17 | 18 | - name: Make an apachectl symlink that is the same between distros 19 | file: 20 | state: link 21 | src: "{{apache_ctl[ansible_os_family]}}" 22 | dest: /usr/local/bin/apachectl 23 | 24 | - name: Apply index.html from template 25 | template: 26 | src: index.j2 27 | dest: /var/www/html/index.html 28 | group: "{{ apache_group[ansible_os_family] }}" 29 | mode: "0644" 30 | 31 | -------------------------------------------------------------------------------- /stable-centos7/Dockerfile: -------------------------------------------------------------------------------- 1 | # Latest version of centos 2 | FROM centos:centos7 3 | MAINTAINER Toshio Kuratomi 4 | RUN yum clean all && \ 5 | yum -y install epel-release && \ 6 | yum -y install PyYAML python-jinja2 python-httplib2 python-keyczar python-paramiko python-setuptools git python-pip 7 | RUN mkdir /etc/ansible/ 8 | RUN echo -e '[local]\nlocalhost' > /etc/ansible/hosts 9 | RUN pip install ansible 10 | -------------------------------------------------------------------------------- /stable-ubuntu14.04/Dockerfile: -------------------------------------------------------------------------------- 1 | # Latest Ubuntu LTS 2 | FROM ubuntu:14.04 3 | MAINTAINER Toshio Kuratomi 4 | RUN apt-get update && \ 5 | apt-get install --no-install-recommends -y software-properties-common && \ 6 | apt-add-repository ppa:ansible/ansible && \ 7 | apt-get update && \ 8 | apt-get install -y ansible 9 | 10 | RUN echo '[local]\nlocalhost\n' > /etc/ansible/hosts 11 | 12 | --------------------------------------------------------------------------------