HELLO WORLD! 
Toshio Kuratomi 
Worked for Red Hat on the Fedora Infrastructure Team 
Little bit of sysadmin work 
Gobs of Python
FUN WITH CONTAINERS 
and 
Toshio Kuratomi
WHAT IS DOCKER? 
Manages Linux containers 
Allows deploying applications in isolation 
Docker Hub ecosystem for distributing general containers
IMAGES 
Made of layers 
Base Images basically OS installs 
Immutable 
Customize by creating a new layer on top
WHAT CAN I DO WITH IT? 
Lightweight cloud 
Tool for encapsulating applications
LIGHTWEIGHT CLOUD 
Lower runtime overhead 
Layered filesystem 
Very quick startup time
ENCAPSULATED APPLICATIONS 
Low overhead 
Run application on startup 
Similar to init
GREAT! SO WHAT'S ANSIBLE GOT TO DO WITH IT?
BUILDING AN IMAGE (DOCKERFILE) 
FROM centos:stable 
RUN yum -y upgrade 
RUN yum install httpd 
COPY httpd.conf /etc/httpd/conf/httpd.conf 
EXPOSE 80 
ENTRYPOINT ["/usr/sbin/apachectl", "-DFOREGOUND"]
BUILDING AN IMAGE (WITH ANSIBLE) 
FROM ansible/centos7-ansible:stable 
ADD ansible /srv/example/ 
WORKDIR /srv/example 
RUN ansible-playbook site.yml -c local 
EXPOSE 80 
ENTRYPOINT ["/usr/sbin/apachectl", "-DFOREGROUND"]
BUILDING AN IMAGE (WITH ANSIBLE) 
ansible/site.yml: 
- hosts: localhost 
tasks: 
- yum: pkg=httpd state=present 
- copy: 
src: httpd.conf 
dest: /etc/httpd/conf/httpd.conf 
group: "apache" 
mode: "0644"
HUH. SO WHAT MAKES ANSIBLE BETTER? 
Power and consistency 
Same method to configure images as your hosts 
Templates and Conditionals 
Portability 
Try out new things via Galaxy roles
A MORE COMPLEX EXAMPLE! 
- hosts: localhost 
vars: 
apache_group: 
Debian: "root" 
RedHat: "apache" 
apache_ctl: 
Debian: "/usr/sbin/apache2ctl" 
RedHat: "/usr/sbin/apachectl"
A MORE COMPLEX EXAMPLE! 
tasks: 
- yum: pkg=httpd state=present 
when: ansible_os_family == "RedHat" 
- apt: update_cache=yes name="apache2" state=present 
when: ansible_os_family == "Debian" 
- name: Make an apachectl symlink that is the same between distros 
file: 
state: link 
src: "{{apache_ctl[ansible_os_family]}}" 
dest: /usr/local/bin/apachectl
A MORE COMPLEX EXAMPLE! 
- name: Apply httpd configuration from template 
template: 
src: httpd.conf.j2 
dest: /etc/httpd/conf/httpd.conf 
group: "{{ apache_group[ansible_os_family] }}" 
mode: "0644"
GALAXY + DOCKER == TRY BEFORE YOU BUY 
FROM ansible/ubuntu14.04-ansible:stable 
RUN mkdir /srv/example 
WORKDIR /srv/example 
ADD site.yml /srv/example/ 
RUN ansible-galaxy install geerlingguy.memcached 
RUN ansible-playbook site.yml -c local 
EXPOSE 11211 
ENTRYPOINT ["/usr/bin/memcached", "-u", "memcache", "-l", "0.0.0.0", "-c" "1024", "-p",
GALAXY + DOCKER == TRY BEFORE YOU BUY 
- hosts: localhost 
roles: 
- role: geerlingguy.memcached
IMAGES FOR BUILDING 
Ansible layered on a Base OS Image 
Building four images 
Two images for Ubuntu-14.04 
Two images for CentOS-7 
An image for Ansible HEAD 
An image for the Ansible release on pypi
CONTACT INFO & RESOURCES 
https://registry.hub.docker.com/u/ansible/centos7-ansible/ 
https://registry.hub.docker.com/u/ansible/ubuntu14.04-ansible/ 
http://ansible.github.com/ansible/ansible-docker-base 
http://ansible.com 
tkuratomi@ansible.com

Fun with containers: Use Ansible to build Docker images

  • 1.
    HELLO WORLD! ToshioKuratomi Worked for Red Hat on the Fedora Infrastructure Team Little bit of sysadmin work Gobs of Python
  • 2.
    FUN WITH CONTAINERS and Toshio Kuratomi
  • 3.
    WHAT IS DOCKER? Manages Linux containers Allows deploying applications in isolation Docker Hub ecosystem for distributing general containers
  • 4.
    IMAGES Made oflayers Base Images basically OS installs Immutable Customize by creating a new layer on top
  • 5.
    WHAT CAN IDO WITH IT? Lightweight cloud Tool for encapsulating applications
  • 6.
    LIGHTWEIGHT CLOUD Lowerruntime overhead Layered filesystem Very quick startup time
  • 7.
    ENCAPSULATED APPLICATIONS Lowoverhead Run application on startup Similar to init
  • 8.
    GREAT! SO WHAT'SANSIBLE GOT TO DO WITH IT?
  • 9.
    BUILDING AN IMAGE(DOCKERFILE) FROM centos:stable RUN yum -y upgrade RUN yum install httpd COPY httpd.conf /etc/httpd/conf/httpd.conf EXPOSE 80 ENTRYPOINT ["/usr/sbin/apachectl", "-DFOREGOUND"]
  • 10.
    BUILDING AN IMAGE(WITH ANSIBLE) FROM ansible/centos7-ansible:stable ADD ansible /srv/example/ WORKDIR /srv/example RUN ansible-playbook site.yml -c local EXPOSE 80 ENTRYPOINT ["/usr/sbin/apachectl", "-DFOREGROUND"]
  • 11.
    BUILDING AN IMAGE(WITH ANSIBLE) ansible/site.yml: - hosts: localhost tasks: - yum: pkg=httpd state=present - copy: src: httpd.conf dest: /etc/httpd/conf/httpd.conf group: "apache" mode: "0644"
  • 12.
    HUH. SO WHATMAKES ANSIBLE BETTER? Power and consistency Same method to configure images as your hosts Templates and Conditionals Portability Try out new things via Galaxy roles
  • 13.
    A MORE COMPLEXEXAMPLE! - hosts: localhost vars: apache_group: Debian: "root" RedHat: "apache" apache_ctl: Debian: "/usr/sbin/apache2ctl" RedHat: "/usr/sbin/apachectl"
  • 14.
    A MORE COMPLEXEXAMPLE! tasks: - yum: pkg=httpd state=present when: ansible_os_family == "RedHat" - apt: update_cache=yes name="apache2" state=present when: ansible_os_family == "Debian" - name: Make an apachectl symlink that is the same between distros file: state: link src: "{{apache_ctl[ansible_os_family]}}" dest: /usr/local/bin/apachectl
  • 15.
    A MORE COMPLEXEXAMPLE! - name: Apply httpd configuration from template template: src: httpd.conf.j2 dest: /etc/httpd/conf/httpd.conf group: "{{ apache_group[ansible_os_family] }}" mode: "0644"
  • 16.
    GALAXY + DOCKER== TRY BEFORE YOU BUY FROM ansible/ubuntu14.04-ansible:stable RUN mkdir /srv/example WORKDIR /srv/example ADD site.yml /srv/example/ RUN ansible-galaxy install geerlingguy.memcached RUN ansible-playbook site.yml -c local EXPOSE 11211 ENTRYPOINT ["/usr/bin/memcached", "-u", "memcache", "-l", "0.0.0.0", "-c" "1024", "-p",
  • 17.
    GALAXY + DOCKER== TRY BEFORE YOU BUY - hosts: localhost roles: - role: geerlingguy.memcached
  • 18.
    IMAGES FOR BUILDING Ansible layered on a Base OS Image Building four images Two images for Ubuntu-14.04 Two images for CentOS-7 An image for Ansible HEAD An image for the Ansible release on pypi
  • 19.
    CONTACT INFO &RESOURCES https://registry.hub.docker.com/u/ansible/centos7-ansible/ https://registry.hub.docker.com/u/ansible/ubuntu14.04-ansible/ http://ansible.github.com/ansible/ansible-docker-base http://ansible.com tkuratomi@ansible.com