Skip to content

create initial structure for ansible-dev and set up the container for Ansible server #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 6, 2024
45 changes: 45 additions & 0 deletions ansible/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# https://docs.docker.com/engine/reference/builder/

# https://hub.docker.com/_/debian
FROM debian:bookworm-slim

# Configure apt not to prompt during docker build
ARG DEBIAN_FRONTEND=noninteractive

# Configure apt to avoid installing recommended and suggested packages
RUN apt-config dump \
| grep -E '^APT::Install-(Recommends|Suggests)' \
| sed -e's/1/0/' \
| tee /etc/apt/apt.conf.d/99no-recommends-no-suggests

# Resynchronize the package index files from their sources
RUN apt-get update

# Install packages
RUN apt-get install -y \
python3 \
python3-pip \
python3-venv \
openssh-client

# Clean up packages: Saves space by removing unnecessary package files
# and lists
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*

# Create a virtual env and install ansible using pip
RUN python3 -m venv /opt/ansible-venv --system-site-packages && \
/opt/ansible-venv/bin/pip install --no-cache-dir ansible

# Create a directory for Ansible configuration
RUN mkdir /etc/ansible/

# Copy local configuration files to the image
COPY ../config/ /etc/ansible/

# Set environment variables for Ansible
ENV PATH="/ansible-venv/bin:$PATH"
ENV ANSIBLE_CONFIG=/etc/ansible/ansible.cfg

# Set the default command to run Ansible
CMD ["ansible", "--version"]
5 changes: 5 additions & 0 deletions config/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[defaults]
inventory = /etc/ansible/hosts
remote_user = root
host_key_checking = False
retry_files_enabled = False
2 changes: 2 additions & 0 deletions config/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[local]
localhost ansible_connection=local
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://docs.docker.com/compose/compose-file/

services:

ansible-dev:
container_name: ansible
build:
context: .
dockerfile: ansible/Dockerfile
volumes:
- ./config/ansible.cfg:/etc/ansible/ansible.cfg
- ./config/hosts:/etc/ansible/hosts
command: sh -c 'trap "exit" TERM; while true; do sleep 1; done'