He aquí una breve demostración de cómo aprovisionar un container Docker usando Playbooks de Ansible. Es una manera fácil de probar nuestros contenedores y nuestros playbooks.
Necesitamos una Dockerfile y un Playbook YAML. Aquí el Dockerfile :
FROM ubuntu:14.04
RUN apt-get update && \
apt-get -y install software-properties-common && \
apt-add-repository -y ppa:ansible/ansible && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y git curl ansible && \
mkdir /opt/myAnsible && \
cd /opt/myAnsible
COPY doSomething.yml /opt/myAnsible/doSomething.yml
WORKDIR /opt/myAnsible
RUN ansible-playbook doSomething.yml --connection=local
CMD ["/bin/bash"]
Aquí un playbook doSomething.yml
:
---
- hosts: localhost
tasks:
- name: hello world
command: uname -a
register: uname
- debug: var=uname.stdout
Entonces ejecutamos:
docker build -t dockans1 .
Y ¡voilà! ¡Trabajo hecho!
Podemos usar un repositorio también. Aquí el nuevo Dockerfile
:
FROM ubuntu:14.04
RUN apt-get update && \
apt-get -y install software-properties-common && \
apt-add-repository -y ppa:ansible/ansible && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y git curl ansible && \
mkdir /opt/myAnsible && \
cd /opt/myAnsible && \
git clone https://github.com/carlessanagustin/ansible-playbooks.git . && \
ansible-playbook provision/hello_world.yml -i 'localhost,' --connection=local
WORKDIR /opt/myAnsible
CMD ["/bin/bash"]
Entonces ejecutamos:
docker build -t dockans2 .
¡Trabajo hecho! Podemos ejecutar
docker images
para ver las imágenes creadas.