commit 91e257bc523e925b0786c9f37b023dc438c1b1a2 Author: Kris Crawford Date: Thu May 29 09:05:20 2025 -0400 Initial save diff --git a/README.md b/README.md new file mode 100644 index 0000000..2c81b22 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# Overview + +## Build steps + +```shell +docker build -t ansible-docker -f ansible-server/Dockerfile . +docker build -t ansible-client -f ansible-client/Dockerfile . +``` + +## Starting containers + +```shell +docker container run -it -v $(pwd):/tmp/ansible ansible-docker bash +for _i in {1..3}; do docker container run --name ansible-client$_i -it -d ansible-client; done +``` + +## Get IP addresses + +```shell +docker ps -q | xargs -n 1 docker inspect --format '{{ .Config.Hostname }} {{ .NetworkSettings.IPAddress }} {{ .Name }}' | sed 's/ \// /' +``` + +## Remove client containers + +```shell +for _c in $(docker container ps -f name=ansible-client -q); do docker container rm $_c -f; done +``` diff --git a/ansible-client/Dockerfile b/ansible-client/Dockerfile new file mode 100644 index 0000000..87ee586 --- /dev/null +++ b/ansible-client/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:22.04 + +RUN apt-get update && apt-get install -y openssh-server +RUN mkdir /var/run/sshd +RUN echo 'root:Passw0rd' | chpasswd +RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config + +# SSH login fix. Otherwise user is kicked off after login +RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd + +EXPOSE 22 + +# run ssh server +CMD ["/usr/sbin/sshd", "-D"] diff --git a/ansible-server/Dockerfile b/ansible-server/Dockerfile new file mode 100644 index 0000000..8ce656d --- /dev/null +++ b/ansible-server/Dockerfile @@ -0,0 +1,54 @@ +FROM python:slim + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + software-properties-common \ + openssh-client \ + sshpass \ + locales \ + bash \ + git \ + curl \ + rsync \ + sudo \ + less \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ + && rm -Rf /usr/share/doc && rm -Rf /usr/share/man + +ARG USERNAME=ansible +ARG USER_UID=1000 +ARG USER_GID=$USER_UID +ENV HOME=/home/$USERNAME +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 pip3 install --no-cache-dir \ + ansible \ + ansible-runner \ + ansible-builder \ + ansible-doctor \ + ansible-later \ + ansible-lint \ + ansible-autodoc + +ENV ANSIBLE_GATHERING=smart +ENV ANSIBLE_HOST_KEY_CHECKING=false +ENV ANSIBLE_RETRY_FILES_ENABLED=false +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 +COPY ./goss.yaml ./goss.yaml +RUN goss validate + +# Set apt frontend back to dialog for interactive prompts +ENV DEBIAN_FRONTEND=dialog diff --git a/ansible-server/goss.yaml b/ansible-server/goss.yaml new file mode 100644 index 0000000..22f41e7 --- /dev/null +++ b/ansible-server/goss.yaml @@ -0,0 +1,34 @@ +user: + ansible: + exists: true + uid: 1000 + gid: 1000 + groups: + - ansible + home: /home/ansible + shell: /bin/bash +group: + ansible: + exists: true + gid: 1000 +command: + ansible: + exit-status: 0 + exec: "ansible --version" + timeout: 30000 + ansible-lint: + exit-status: 0 + exec: "ansible-lint --version" + timeout: 30000 + bash: + exit-status: 0 + exec: "bash -version" + curl: + exit-status: 0 + exec: "curl --version" + git: + exit-status: 0 + exec: "git version" + pip: + exit-status: 0 + exec: "pip3 -V"