data-only containers for ansible automation

Hi, I did a playbook to create my PoCs much faster (from days to one hour). And got some issues with my Mac. My python got broken :/

Then I’ve decided to manage my playbook thru containers (Check my project here). However, managing data from those, brings a portability issue. Then, to make it simple. I started to use data-only containers.

I’ve got the the idea from posts:

My Dockerfile

I defined this docker file:

FROM centos:7.3.1611

# Install all packages
RUN yum -y install epel-release && yum clean all
RUN curl "" -o ""
RUN python
RUN yum -y install ansible && yum clean all
RUN yum -y install vim && yum clean all
RUN yum -y install curl && yum clean all
RUN yum -y install git && yum clean all

# install sdk from nuage
RUN pip install vspk
RUN pip install pexpect
RUN pip install packet-python
RUN pip install django

# Generate user dev and his files
RUN useradd dev
RUN mkdir -p /home/dev/.ssh
RUN mkdir -p /home/dev/images
RUN mkdir -p /home/dev/packet-nuagevns
RUN mkdir -p /var/log/ansible
RUN chown -R dev:dev /home/dev
RUN chown -R dev:dev /var/log/ansible
VOLUME /home/dev/packet-nuagevns
VOLUME /home/dev/.ssh
VOLUME /var/log/ansible
WORKDIR /home/dev
ENV HOME /home/dev
ADD vimrc /home/dev/.vimrc
ADD /home/dev/
ADD .packet_token /home/dev/.packet_token
ADD .packet_project_id /home/dev/.packet_project_id
ADD .nuage_license_key /home/dev/.nuage_license_key
RUN chmod 755 /home/dev/
ADD bash_profile /home/dev/.bash_profile
RUN mkdir -p /home/dev/.vim/autoload /home/dev/.vim/bundle
RUN curl -LSso /home/dev/.vim/autoload/pathogen.vim
RUN git clone git://  /home/dev/.vim/bundle/vim-ansible-yaml
RUN git clone /home/dev/.vim/bundle/vim-jinja
RUN git clone git:// --recursive /home/dev/ansible

RUN chown -R dev: /home/dev
USER dev
CMD /home/dev/

You can see that I’ve defined three volumes:

VOLUME /home/dev/packet-nuagevns
VOLUME /home/dev/.ssh
VOLUME /var/log/ansible

Those volumes are persistent among containers. I built my image thru

docker build -t p1nrojas/packet-nuagevns . >> /tmp/install.log

Now, creates you container as the following. Data-only container don’t have to be running:

docker run -d --name vns-data-only p1nrojas/packet-nuagevns true

I’ve created a file to manage the first action on it, and install my app files.


if [ ! -f /var/log/ansible/ansible-packet-nuagevns.log ]; then
    echo "There is not data. Proceed setup"
    git clone ~/packet-nuagevns
    touch /var/log/ansible/ansible-packet-nuagevns.log
    ssh-keygen -t rsa -b 4096 -C "" -f ~/.ssh/id_rsa -q -N ""
    cd /home/dev/packet-nuagevns
    ansible-playbook build.yml
    echo "Caution: user data detected. skipping setup. Next time override CMD"

And then, you just need to run the follow to install your files.

docker run -d -i -t --volumes-from vns-data-only --name vns-packet p1nrojas/packet-nuagevns

You can run as many container you want on that data-only container.

See ya!

Categories: containers, DevOps

Tagged as: , , , ,

2 replies »

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: