ansible/test-docker.sh

28 lines
750 B
Bash
Raw Normal View History

#!/bin/bash
2022-12-19 12:59:24 +00:00
user="${USER:-"root"}"
function playbook() {
book="${1:-"site.yml"}"
opts=""
[ ! -z "$2" ] && opts="-t $2"
ansible-playbook "$book" "$opts" -i docker.ini
}
case "$1" in
play)
2022-12-19 12:59:24 +00:00
book="${2:-"site.yml"}"
# opts=""
# [ ! -z "$3" ] && opts="-t $3"
ansible-playbook "$book" -i docker.ini;;
# playbook "$2" "$3";;
2022-12-19 12:59:24 +00:00
kill) docker kill ansible;;
run)
docker run --rm --name ansible -id alpine
[ "$?" == "0" ] && docker exec ansible /bin/sh -c "apk update && apk add python3"
ansible -i docker.ini all -m ping;;
2022-12-19 12:59:24 +00:00
zsh) docker exec -itu "$user" ansible zsh;;
*sh) docker exec -it ansible "$1";;
"") echo "Usage: $0 [run|kill|play|zsh|*sh|{container cmd}]";;
*) docker exec -itu "$user" ansible $@;;
esac