Skip to content

Instantly share code, notes, and snippets.

@Tzrlk
Created December 27, 2017 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tzrlk/038029b6cdb7fca8c98b5cb4de74a92a to your computer and use it in GitHub Desktop.
Save Tzrlk/038029b6cdb7fca8c98b5cb4de74a92a to your computer and use it in GitHub Desktop.
This script makes sure an ansible container is perpetually running and lets you exec scripts on it.
#!/bin/bash -e
CONTAINER_NAME=ansible
function dpsgrep() {
pattern=${1} && shift
docker ps --format="{{ .Names }}" ${*} \
| grep -q ${pattern}
return ${?}
}
if ! $(dpsgrep "${CONTAINER_NAME}"); then
echo "Container isn't running, checking if created."
if ! $(dpsgrep "${CONTAINER_NAME}" --all); then
echo "Container not created. Starting creation."
docker container create \
--name ${CONTAINER_NAME} \
--entrypoint sh \
--tty \
--volume "${HOME}/.ansible://root/.ansible" \
williamyeh/ansible:alpine3
fi
echo "Container existence ensured. Starting container."
docker container start ansible
fi
docker container exec -it ansible ansible ${*}
@ECHO OFF
SETLOCAL
SET WORK=%~dp0
SET WORK=%WORK:~0,-1%
sh %WORK%/ansible %*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment