-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexec-playbook
More file actions
34 lines (26 loc) · 882 Bytes
/
exec-playbook
File metadata and controls
34 lines (26 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
set -xeuo pipefail
[[ -z ${IP:-} ]] && {
echo "Environment variable [IP] is not defined. Cannot continue."
exit 1
}
[[ -z ${PLAYBOOK:-} ]] && {
echo "Environment variable [PLAYBOOK] is not defined. Cannot continue."
exit 1
}
[[ -e ${PLAYBOOK} ]] || {
echo "Ansible playbook defined in environment variable [PLAYBOOK] has a value of [${PLAYBOOK}]; however it doesnt exist. Cannot continue."
exit 1
}
pkey_file=/root/.ssh/id_rsa
[[ -n ${PRIVATE_KEY_FILE:-} ]] && {
pkey_file=${PRIVATE_KEY_FILE}
}
[[ -e ${pkey_file} ]] || {
echo "No private ssh key has been found. By default, [/root/.ssh/id_rsa] is checked, you can override with the [PRIVATE_KEY_FILE] environment variable."
exit 1
}
gw=$(ip r|grep -Po 'default via \S+'|awk '{print $3}')
arping ${gw} -c1
ping ${gw} -c1
ansible-playbook --ssh-extra-args="-i ${pkey_file}" -u root -i ${IP}, ${PLAYBOOK}