Initial save
This commit is contained in:
commit
91e257bc52
27
README.md
Normal file
27
README.md
Normal file
@ -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
|
||||||
|
```
|
14
ansible-client/Dockerfile
Normal file
14
ansible-client/Dockerfile
Normal file
@ -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"]
|
54
ansible-server/Dockerfile
Normal file
54
ansible-server/Dockerfile
Normal file
@ -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
|
34
ansible-server/goss.yaml
Normal file
34
ansible-server/goss.yaml
Normal file
@ -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"
|
Loading…
x
Reference in New Issue
Block a user