diff --git a/Dockerfile b/Dockerfile index 1a4dad1af32e2ffc079d71cead946b3af650818a..9979db1f74182d3b98297c38446d09cd093ee9e8 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 a6ea4b42ea2233550738534eee8dbef71c27ff34..bc9d2bf3023eb060bdf094e0bdb865f694ef850e 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