-
Notifications
You must be signed in to change notification settings - Fork 1
/
molecule-scp
41 lines (32 loc) · 908 Bytes
/
molecule-scp
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
35
36
37
38
39
40
41
#!/bin/bash
# vim:ts=2:syntax=sh:ai:number
# Where are we
#------------------------------------------------------------
while :
do
[[ -d molecule ]] && break
if [[ $PWD == $HOME ]]
then
echo "error: could not find molecule path" >&2
exit 1
fi
cd ..
done
molecule list \
| awk '$3 ~ "ansible" && $5 ~ "true" { print $1,$4 }' \
| while read a b
do
Config=~/.cache/molecule/$( basename $PWD )/$b/instance_config.yml
awk -F':' '/address|instance|user|identity_file/ { print $2 }' $Config \
| paste - - - - \
| awk -v file="$1" \
'{ print "scp -o user="$4" -i "$2" "file" "$1":/tmp/." }'
if [[ ! -z $2 ]]
then
awk -F':' '/address|instance|user|identity_file/ { print $2 }' $Config \
| paste - - - - \
| awk -v file="$( basename $1 )" -v dest="$2" \
'{ print "ssh -o user="$4" -i "$2" "$1" sudo cp /tmp/"file" "dest }'
fi
done \
| sort -u