├── README.md └── Dockerfile /README.md: -------------------------------------------------------------------------------- 1 | # ansible_container 2 | Looking to place Ansible in a container (i.e. run Ansible in a container to manage other stuff). 3 | 4 | If you want to exclude items from the Docker build place the details of them in a .dockerignore file, then make sure to put the .dockerignore file into a .gitignore file as well. 5 | 6 | Docker container - https://hub.docker.com/repository/docker/geektechstuff/ansible_container 7 | 8 | Blog post at: https://geektechstuff.com/2020/02/10/ansible-in-a-docker-container/ 9 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # geektechstuff 2 | # using a lot of https://hub.docker.com/r/philm/ansible_playbook/dockerfile/ 3 | 4 | # Alpine is a lightweight version of Linux. 5 | # apline:latest could also be used 6 | FROM alpine:3.7 7 | 8 | RUN \ 9 | # apk add installs the following 10 | apk add \ 11 | curl \ 12 | python \ 13 | py-pip \ 14 | py-boto \ 15 | py-dateutil \ 16 | py-httplib2 \ 17 | py-jinja2 \ 18 | py-paramiko \ 19 | py-setuptools \ 20 | py-yaml \ 21 | openssh-client \ 22 | bash \ 23 | tar && \ 24 | pip install --upgrade pip 25 | 26 | # Makes the Ansible directories 27 | RUN mkdir /etc/ansible /ansible 28 | RUN mkdir ~/.ssh 29 | 30 | # Over rides SSH Hosts Checking 31 | RUN echo "host *" >> ~/.ssh/config &&\ 32 | echo "StrictHostKeyChecking no" >> ~/.ssh/config 33 | 34 | # Downloads the Ansible tar (curl) and saves it (-o) 35 | RUN \ 36 | curl -fsSL https://releases.ansible.com/ansible/ansible-2.9.3.tar.gz -o ansible.tar.gz 37 | # Extracts Ansible from the tar file 38 | RUN \ 39 | tar -xzf ansible.tar.gz -C ansible --strip-components 1 && \ 40 | rm -fr ansible.tar.gz /ansible/docs /ansible/examples /ansible/packaging 41 | 42 | # Makes a directory for ansible playbooks 43 | RUN mkdir -p /ansible/playbooks 44 | # Makes the playbooks directory the working directory 45 | WORKDIR /ansible/playbooks 46 | 47 | # Sets environment variables 48 | ENV ANSIBLE_GATHERING smart 49 | ENV ANSIBLE_HOST_KEY_CHECKING False 50 | ENV ANSIBLE_RETRY_FILES_ENABLED False 51 | ENV ANSIBLE_ROLES_PATH /ansible/playbooks/roles 52 | ENV ANSIBLE_SSH_PIPELINING True 53 | ENV PATH /ansible/bin:$PATH 54 | ENV PYTHONPATH /ansible/lib 55 | 56 | # Sets entry point (same as running ansible-playbook) 57 | ENTRYPOINT ["ansible-playbook"] 58 | # Can also use ["ansible"] if wanting it to be an ad-hoc command version 59 | #ENTRYPOINT ["ansible"] 60 | --------------------------------------------------------------------------------