From 2630b6a88d46e4b6e10713d4d6ccddb3a63dd68f Mon Sep 17 00:00:00 2001 From: Kris Crawford Date: Mon, 2 Jun 2025 08:00:04 -0400 Subject: [PATCH] Adding docker to ansible-server --- README.md | 6 +++--- ansible-server/Dockerfile | 19 ++++++++++++++++--- ansible-server/goss.yaml | 7 +++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2c81b22..8c6f0b3 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ ## Build steps ```shell -docker build -t ansible-docker -f ansible-server/Dockerfile . -docker build -t ansible-client -f ansible-client/Dockerfile . +docker build -t ansible-server:0.0.2 -f ansible-server/Dockerfile . +docker build -t ansible-client:0.0.1 -f ansible-client/Dockerfile . ``` ## Starting containers ```shell -docker container run -it -v $(pwd):/tmp/ansible ansible-docker bash +docker container run -it -v $(pwd):/tmp/ansible -v /var/run/docker.sock:/var/run/docker.sock ansible-server:0.0.2 bash for _i in {1..3}; do docker container run --name ansible-client$_i -it -d ansible-client; done ``` diff --git a/ansible-server/Dockerfile b/ansible-server/Dockerfile index 8ce656d..cc9c26f 100644 --- a/ansible-server/Dockerfile +++ b/ansible-server/Dockerfile @@ -4,6 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update \ && apt-get install -y --no-install-recommends \ + ca-certificates \ software-properties-common \ openssh-client \ sshpass \ @@ -13,8 +14,20 @@ RUN apt-get update \ curl \ rsync \ sudo \ - less \ - && apt-get clean \ + less + +# Install docker +RUN curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc +RUN chmod a+r /etc/apt/keyrings/docker.asc +RUN echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null +RUN apt-get update -y +RUN apt-get install -y docker-ce docker-ce-cli +VOLUME /var/run/docker.sock + +RUN apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ && rm -Rf /usr/share/doc && rm -Rf /usr/share/man @@ -26,6 +39,7 @@ RUN groupadd --gid $USER_GID $USERNAME RUN useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL >/etc/sudoers.d/$USERNAME RUN chmod 0440 /etc/sudoers.d/$USERNAME +RUN sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/' /home/ansible/.bashrc RUN pip3 install --no-cache-dir \ ansible \ @@ -43,7 +57,6 @@ ENV ANSIBLE_FORCE_COLOR=true ENV GOSS_FMT=documentation ENV GOSS_COLOR=true - # Install goss for testing RUN curl -L https://github.com/goss-org/goss/releases/latest/download/goss-linux-amd64 -o /usr/local/bin/goss RUN chmod +rx /usr/local/bin/goss diff --git a/ansible-server/goss.yaml b/ansible-server/goss.yaml index 22f41e7..917d236 100644 --- a/ansible-server/goss.yaml +++ b/ansible-server/goss.yaml @@ -16,6 +16,10 @@ command: exit-status: 0 exec: "ansible --version" timeout: 30000 + ansible-builder: + exit-status: 0 + exec: "ansible-builder --version" + timeout: 30000 ansible-lint: exit-status: 0 exec: "ansible-lint --version" @@ -26,6 +30,9 @@ command: curl: exit-status: 0 exec: "curl --version" + docker: + exit-status: 0 + exec: "docker --version" git: exit-status: 0 exec: "git version"