Installation

Build ansible docker container

Dockerfile using ubuntu image

FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
  apt-get install -y gcc python3-dev libkrb5-dev && \
  apt-get install python3-pip -y && \
  pip3 install --upgrade pip && \
  pip3 install --upgrade virtualenv && \
  pip3 install pywinrm[kerberos] && \
  apt install krb5-user -y && \ 
  pip3 install pywinrm && \
  pip3 install ansible && \
  pip3 install ansible-pylibssh && \
  pip3 install paramiko
WORKDIR /ansible

Dockerfile using python image

  • This also run as user and use python venv

Build Docker Image

  • Docker build commad: docker build -t ansible . [--build-arg USER=$USER]

  • Run ansible container: docker run -it ansible ansible

  • docker run --mount type=bind,source="$(pwd)"/ansible,target=/home/$USER/ansible -v ~/.ssh:/home/$USER/.ssh:ro --rm -it --name ansible ansible /bin/bash

    • this command mount ansible folder and .ssh folder

    • if using mount option, the ansible folder in host must be created before running the command

    • using bind, the ansible folder in host will be owned by current user, using -v (volume), the username in host will be owned by root

Reference

  • https://4sysops.com/archives/how-to-deploy-ansible-inside-a-docker-container/

Last updated