Просмотр исходного кода

run the playbook on multiple hosts with different credentials with this script

pull/1980/head
mcnesium 3 лет назад
Родитель
Сommit
bd75994290
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 7D6CC73E428F633F
3 измененных файлов: 40 добавлений и 0 удалений
  1. +1
    -0
      docs/configuring-playbook.md
  2. +7
    -0
      examples/host.yml
  3. +32
    -0
      inventory/scripts/ansible-all-hosts.sh

+ 1
- 0
docs/configuring-playbook.md Просмотреть файл

@@ -18,6 +18,7 @@ You can then follow these steps inside the playbook directory:


1. edit the inventory hosts file (`inventory/hosts`) to your liking 1. edit the inventory hosts file (`inventory/hosts`) to your liking


1. if you want to run multiple servers with different credentials, you can copy the sample inventory hosts yaml file for each of your hosts: (`cp examples/host.yml inventory/my_host1.yml` …) and use the [`ansible-all-hosts.sh`](inventory/scripts/ansible-all-hosts.sh) script [in then next step](installing.md).


For a basic Matrix installation, that's all you need. For a basic Matrix installation, that's all you need.
For a more custom setup, see the [Other configuration options](#other-configuration-options) below. For a more custom setup, see the [Other configuration options](#other-configuration-options) below.


+ 7
- 0
examples/host.yml Просмотреть файл

@@ -0,0 +1,7 @@
matrix_servers:
hosts:
matrix.<your domain>:
ansible_host: <your server's external ip address>
ansible_ssh_user: <your ssh user>
become: true
become_user: root

+ 32
- 0
inventory/scripts/ansible-all-hosts.sh Просмотреть файл

@@ -0,0 +1,32 @@
#!/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.
#
# ./inventory/scripts/ansible-all-hosts.sh self-check
#

# set inventory directory path
inventory=$(dirname "$(readlink -f "$0")")/../../inventory

# 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 "$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 setup.yml \
--inventory-file "$host" \
--extra-vars "ansible_become_pass=${pws[$host]}" \
--tags="$tags"
done

Загрузка…
Отмена
Сохранить