-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflockrc
More file actions
110 lines (98 loc) · 2.26 KB
/
flockrc
File metadata and controls
110 lines (98 loc) · 2.26 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# _______ _____ _______ _ _
# |______ | | | | |____/
# | |_____ |_____| |_____ | \_
#
flock_root=$(cd $(dirname "${BASH_SOURCE}");pwd -P)
PATH=${PATH}:${flock_root}/bin
### ansible
ansiblerc="${HOME}/ansible/hacking/env-setup"
if test -r ${ansiblerc} ; then
source ${ansiblerc} &> /dev/null
fi
# Main flock wrapper function
# flock on changes ansible inventory
function flock() {
if [ "$1" == "ls" ] ; then
if ! test -d ./inventory ; then
return 1
fi
if test -r ./inventory/${2}.ansible; then
cat ./inventory/${2}.ansible
return $?
fi
for i in ./inventory/*.ansible; do
i=$(basename $i)
echo ${i%%.ansible}
done
return $?
fi
if [ "$1" != "on" ] ; then
$(which flock) $*
return $?
fi
shift
local _inventory=./inventory/${1:-hosts}.ansible
if test -f ${_inventory} ; then
_inventory=$(cd ./inventory;pwd)/${1:-hosts}.ansible
export ANSIBLE_HOSTS=${_inventory}
else
echo "Not found: ${_inventory}"
fi
}
function stack() {
if [ "$1" == "ls" ] ; then
if ! test -d ./inventory ; then
return 1
fi
if test -r ./inventory/${2}.cmonkey; then
cat ./inventory/${2}.cmonkey
return $?
fi
for i in ./inventory/*.cmonkey; do
i=$(basename $i)
echo ${i%%.cmonkey}
done
return $?
fi
if [ "$1" != "on" ] ; then
$(which stack) $*
return $?
fi
shift
local _inventory=./inventory/${1:-hosts}.cmonkey
if test -f ${_inventory} ; then
_inventory=$(cd ./inventory;pwd)/${1:-hosts}.cmonkey
export CMONKEY_HOSTS=${_inventory}
else
echo "Not found: ${_inventory}"
fi
}
function flack() {
local _flock=$(echo "$*" | cut -d@ -f 1)
local _stack=$(echo "$*" | cut -d@ -f 2)
flock on ${_flock}
stack on ${_stack}
}
function inventory() {
if test -n "${ANSIBLE_HOSTS}" ; then
local _inventory=${ANSIBLE_HOSTS}
if test -f ${_inventory} ; then
echo ""
cat ${_inventory}
fi
fi
if test -n "${CMONKEY_HOSTS}" ; then
_inventory=${CMONKEY_HOSTS}
if test -f ${_inventory} ; then
echo ""
cat ${_inventory}
fi
fi
}
function cmonkey() {
local _opts=""
if test -f "${CMONKEY_HOSTS}"; then
_opts="-c ${CMONKEY_HOSTS}"
fi
cloudmonkey ${_opts} $*
}