From 583fcccac0be310ed3daf06863262e8733a7cebe Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sun, 20 Apr 2025 12:26:51 -0700
Subject: [PATCH] Add SSH key mounting to the image

---
 Dockerfile | 23 ++++++++++++++++++++---
 README.md  | 10 ++++++++--
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 1a4dad1..9979db1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,13 +4,30 @@ FROM alpine:${ALPINE_VERSION}
 ARG ANSIBLE_VERSION=2
 RUN apk add --update --no-cache \
     # Install latest version of these dependencies \
-    bash openssh sshpass rsync \
-    # Install a specific version of ansible-core with the latest compatible ansible \
+    bash openssh python3 sshpass rsync \
+    # Install specific version of ansible-core and latest compatible ansible \
     ansible ansible-core~=${ANSIBLE_VERSION}
 
+# Add entrypoint script
+COPY <<EOF /entrypoint.sh
+#!/bin/sh
+set -e
+
+cp -R /tmp/.ssh /root/.ssh
+chown -R root:root /root/.ssh
+
+exec "\$@"
+EOF
+
+RUN chmod +x /entrypoint.sh
+ENTRYPOINT ["/entrypoint.sh"]
+
+# Make sure the temporary SSH directory exists since we reference it in the
+# entrypoint script
+RUN mkdir /tmp/.ssh
+
 WORKDIR /ansible
 
-ENTRYPOINT []
 CMD ["ansible", "--help"]
 
 # vi: set ts=4 sw=4 et ft=dockerfile:
diff --git a/README.md b/README.md
index a6ea4b4..bc9d2bf 100644
--- a/README.md
+++ b/README.md
@@ -11,10 +11,16 @@ Images are tagged with the version of `ansible-core` included in the image. Ther
 
 ## Usage
 
-The working directory is `/ansible`, so mount your ansible playbooks and inventory files into that direcotry.
+The working directory is `/ansible`, so mount your ansible playbooks and inventory files into that directory.
 
 ```bash
-docker run --rm -it -v $(pwd):/ansible ccoley/ansible:latest ansible -m ping
+docker run --rm -it -v $(pwd):/ansible ccoley/ansible:latest ansible -m ping all
+```
+
+If you want to use your local SSH keys, known_hosts, and config in the container then mount them to `/tmp/.ssh` in the container.
+
+```bash
+docker run --rm -it -v $(pwd):/ansible -v ~/.ssh:/tmp/.ssh:ro ccoley/ansible:latest ansible -m ping all
 ```
 
 ## Building Images Locally
-- 
GitLab