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.
 
 

33 lines
864 B

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