2022-03-24 15:18:47 +00:00
|
|
|
#!/bin/bash
|
2022-12-19 12:59:24 +00:00
|
|
|
user="${USER:-"root"}"
|
2022-03-23 01:03:04 +00:00
|
|
|
|
|
|
|
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;;
|
2022-03-23 01:03:04 +00:00
|
|
|
# playbook "$2" "$3";;
|
2022-12-19 12:59:24 +00:00
|
|
|
kill) docker kill ansible;;
|
2022-03-23 01:03:04 +00:00
|
|
|
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 $@;;
|
2022-03-23 01:03:04 +00:00
|
|
|
esac
|