Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
971 B

  1. #!/usr/bin/env bash
  2. # SPDX-FileCopyrightText: 2024 MDAD Team and contributors
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. #
  6. # Run the playbook on multiple hosts with different credentials with this script
  7. # It defaults to ansible tags "setup-all,start". You can pass alternative tags
  8. # to this script as arguments, e.g.
  9. #
  10. # ./bin/ansible-all-hosts.sh self-check
  11. #
  12. # set playbook root path
  13. root=$(dirname "$(readlink -f "$0")")/..
  14. # set default tags or get from first argument if any
  15. tags="${1:-setup-all,start}"
  16. # init password array
  17. declare -A pws
  18. # capture passwords for all hosts
  19. for host in "$root"/inventory/*.yml; do
  20. read -rp "sudo password for $(basename "$host"): " -s pw
  21. pws[$host]="$pw"
  22. echo
  23. done
  24. # run ansible on all captured passwords/hosts
  25. for host in "${!pws[@]}"; do
  26. ansible-playbook "$root"/setup.yml \
  27. --inventory-file "$host" \
  28. --extra-vars "ansible_become_pass=${pws[$host]}" \
  29. --tags="$tags"
  30. done