Created
December 27, 2017 02:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ${*} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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