matrix-docker-ansible-deploy/bin/ansible-all-hosts.sh
Suguru Hirahara 000790ad76
Setting up REUSE: add copyright statements to files in bin/
Signed-off-by: Suguru Hirahara <acioustick@noreply.codeberg.org>
2024-12-08 05:00:44 +09:00

38 lines
971 B
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2024 MDAD Team and contributors
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# 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.
#
# ./bin/ansible-all-hosts.sh self-check
#
# set playbook root path
root=$(dirname "$(readlink -f "$0")")/..
# 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