Skip to content

Commit 9c7544c

Browse files
Merge pull request #9 from creativecommons/ansible-container
create initial structure for ansible-dev and set up the container for Ansible server
2 parents d6962fa + 4f58bed commit 9c7544c

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

ansible/Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# https://docs.docker.com/engine/reference/builder/
2+
3+
# https://hub.docker.com/_/debian
4+
FROM debian:bookworm-slim
5+
6+
# Configure apt not to prompt during docker build
7+
ARG DEBIAN_FRONTEND=noninteractive
8+
9+
# Configure apt to avoid installing recommended and suggested packages
10+
RUN apt-config dump \
11+
| grep -E '^APT::Install-(Recommends|Suggests)' \
12+
| sed -e's/1/0/' \
13+
| tee /etc/apt/apt.conf.d/99no-recommends-no-suggests
14+
15+
# Resynchronize the package index files from their sources
16+
RUN apt-get update
17+
18+
# Install packages
19+
RUN apt-get install -y \
20+
python3 \
21+
python3-pip \
22+
python3-venv \
23+
openssh-client
24+
25+
# Clean up packages: Saves space by removing unnecessary package files
26+
# and lists
27+
RUN apt-get clean
28+
RUN rm -rf /var/lib/apt/lists/*
29+
30+
# Create a virtual env and install ansible using pip
31+
RUN python3 -m venv /opt/ansible-venv --system-site-packages && \
32+
/opt/ansible-venv/bin/pip install --no-cache-dir ansible
33+
34+
# Create a directory for Ansible configuration
35+
RUN mkdir /etc/ansible/
36+
37+
# Copy local configuration files to the image
38+
COPY ../config/ /etc/ansible/
39+
40+
# Set environment variables for Ansible
41+
ENV PATH="/ansible-venv/bin:$PATH"
42+
ENV ANSIBLE_CONFIG=/etc/ansible/ansible.cfg
43+
44+
# Set the default command to run Ansible
45+
CMD ["ansible", "--version"]

config/ansible.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[defaults]
2+
inventory = /etc/ansible/hosts
3+
remote_user = root
4+
host_key_checking = False
5+
retry_files_enabled = False

config/hosts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[local]
2+
localhost ansible_connection=local

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://docs.docker.com/compose/compose-file/
2+
3+
services:
4+
5+
ansible-dev:
6+
container_name: ansible
7+
build:
8+
context: .
9+
dockerfile: ansible/Dockerfile
10+
volumes:
11+
- ./config/ansible.cfg:/etc/ansible/ansible.cfg
12+
- ./config/hosts:/etc/ansible/hosts
13+
command: sh -c 'trap "exit" TERM; while true; do sleep 1; done'

0 commit comments

Comments
 (0)