diff --git a/Dockerfile b/Dockerfile index c3f29cf7e5fb3f06b8fec6e771d0b680da09f5c6..fb6e25ca5d7f309c0727f4c56e7384d5e7fa03aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,14 +8,20 @@ RUN apk add --update --no-cache \ # Install specific version of ansible-core and latest compatible ansible \ ansible ansible-core~=${ANSIBLE_VERSION} -# Add entrypoint script +# Add an entrypoint script that copies files from the /tmp/home directory into +# the actual home directory +RUN mkdir -p /tmp/home COPY entrypoint.sh / 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 +# Set VIM as the default editor. Used by 'ansible-vault edit' +ENV EDITOR=/usr/bin/vim + +# Add some useful aliases for instances where we want to log into the container +# and debug stuff +ENV ENV=/etc/profile +RUN echo "alias ll='ls -alFh'" >> /etc/profile.d/aliases.sh WORKDIR /ansible diff --git a/README.md b/README.md index bc9d2bf3023eb060bdf094e0bdb865f694ef850e..c18498fc1aab1279691310c9a5d22a2a60c318ba 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ The working directory is `/ansible`, so mount your ansible playbooks and invento 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. +If you want to use any files/directories in your home directory from within the container, then you can mount them to `/tmp/home` in the container and they'll be copied to the container user's home directory. This is useful for SSH keys and known_hosts, auth configurations, etc. ```bash -docker run --rm -it -v $(pwd):/ansible -v ~/.ssh:/tmp/.ssh:ro ccoley/ansible:latest ansible -m ping all +docker run --rm -it -v $(pwd):/ansible -v ~/.ssh:/tmp/home/.ssh:ro ccoley/ansible:latest ansible -m ping all ``` ## Building Images Locally diff --git a/entrypoint.sh b/entrypoint.sh index 2ac80a8ebfc2aa2d783a9944b0c0e698bdca8460..94afd5872ae5403f5ac1d251973fc2845a518954 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,8 @@ #!/bin/sh set -e -cp -R /tmp/.ssh /root/.ssh -chown -R root:root /root/.ssh +# Copy and chown files to the root user's home directory +rsync -rlp /tmp/home/ /root/ exec "$@"