Categories
Containers

Docker bash integration

Example Dockerfile

FROM ubuntu:bionic-20200219

ARG TERRAFORM_VERSION="0.12.23"
# TODO: currnet ubuntu ansible version 2.5.1 update to use variable
# TODO: reduce size of image is pip or binary tarball better
ARG ANSIBLE_VERSION="2.5.1"
ARG PACKER_VERSION="1.5.4"
ARG AWSCLI_VERSION="1.18.19"

LABEL maintainer="Praison <contact@example.com>"
LABEL terraform_version=${TERRAFORM_VERSION}
LABEL ansible_version=${ANSIBLE_VERSION}
LABEL aws_cli_version=${AWSCLI_VERSION}

ENV DEBIAN_FRONTEND=noninteractive
ENV AWSCLI_VERSION=${AWSCLI_VERSION}
ENV TERRAFORM_VERSION=${TERRAFORM_VERSION}
ENV PACKER_VERSION=${PACKER_VERSION}
RUN apt-get update \
    && apt-get install -y ansible curl python3 python3-pip python3-boto unzip  \
    && pip3 install --upgrade awscli==${AWSCLI_VERSION} \
    && curl -LO https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
    && curl -LO https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip \
    && unzip '*.zip' -d /usr/local/bin \
    && rm *.zip

RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

CMD    ["/bin/bash"]

Building Docker Image

docker build -t praison/ansible-packer-terraform .

Examples getting versions

docker run --rm praison/ansible-packer-terraform terraform -version
docker run --rm praison/ansible-packer-terraform packer -version
docker run --rm praison/ansible-packer-terraform ansible --version
docker run --rm praison/ansible-packer-terraform aws --version

Bash Integration

Add it to

.bashrc or .bash_profile

It also maps your .ssh and .aws folders to share keys and configs that the command might need.

pansible () 
{
  docker run --rm \
             -w /opt \
             -v $(pwd):/opt/ \
             -v ~/.aws:/root/.aws \
             -v ~/.ssh:/root/.ssh \
             praison/ansible-packer-terraform ansible $@
}

paws () 
{
  docker run --rm \
             -w /opt \
             -v $(pwd):/opt/ \
             -v ~/.aws:/root/.aws \
             -v ~/.ssh:/root/.ssh \
             praison/ansible-packer-terraform aws $@
}

ppacker () 
{
  docker run --rm \
             -w /opt \
             -v $(pwd):/opt/ \
             -v ~/.aws:/root/.aws \
             -v ~/.ssh:/root/.ssh \
             praison/ansible-packer-terraform packer $@
}

pterraform () 
{
  docker run --rm \
             -w /opt \
             -v $(pwd):/opt/ \
             -v ~/.aws:/root/.aws \
             -v ~/.ssh:/root/.ssh \
             praison/ansible-packer-terraform terraform $@
}

Example usage:

$ ppacker -version
1.5.4

$ pansible --version
ansible 2.5.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Nov  7 2019, 10:07:09) [GCC 7.4.0]