2022-07-26 13:34:55 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Run the playbook on multiple hosts with different credentials with this script
|
|
|
|
# It defaults to ansible tags "setup-all,start". You can pass alternative tags
|
|
|
|
# to this script as arguments, e.g.
|
|
|
|
#
|
2024-01-09 17:13:10 +00:00
|
|
|
# ./bin/ansible-all-hosts.sh self-check
|
2022-07-26 13:34:55 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
# set playbook root path
|
2024-01-23 10:09:52 +00:00
|
|
|
root=$(dirname "$(readlink -f "$0")")/..
|
2022-07-26 13:34:55 +00:00
|
|
|
|
|
|
|
# set default tags or get from first argument if any
|
|
|
|
tags="${1:-setup-all,start}"
|
|
|
|
|
|
|
|
# init password array
|
|
|
|
declare -A pws
|
|
|
|
|
|
|
|
# capture passwords for all hosts
|
|
|
|
for host in "$root"/inventory/*.yml; do
|
|
|
|
read -rp "sudo password for $(basename "$host"): " -s pw
|
|
|
|
pws[$host]="$pw"
|
|
|
|
echo
|
|
|
|
done
|
|
|
|
|
|
|
|
# run ansible on all captured passwords/hosts
|
|
|
|
for host in "${!pws[@]}"; do
|
|
|
|
ansible-playbook "$root"/setup.yml \
|
|
|
|
--inventory-file "$host" \
|
|
|
|
--extra-vars "ansible_become_pass=${pws[$host]}" \
|
|
|
|
--tags="$tags"
|
|
|
|
done
|