-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_clish_command.sh
executable file
·101 lines (79 loc) · 2.19 KB
/
run_clish_command.sh
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
#!/bin/bash
save_output=0
show_output=1
vault_pass_prompt=0
clish_cmd="'show hostname'"
print_usage() {
cat - <<EOF
Run arbitrary CLISH command on Check Point hosts and VSX Virtual Systems
Usage: $0 [ -l <list of targets> ] [ -i inventory ] [ -h ] [-c <command>]
i Specify an inventory (optional; default to inventory.yml in local dir)
k Keep the generated script on both Ansible controller and remote host; default is to remove scripts
l List of targets, comma-separated; defaults to all hosts
s Save output to clish_output/ directory
c CLISH command to run; default: "show hostname"
u Optional Gaia admin user name, if you need to override inventory or vars.yml
I ignore errors from CLISH; default is to fail if CLISH returns non-zero result
This is useful if you're trying to compare hosts with mismatched configs, like VSX gateways
O Do NOT show output on console (default is to show output); recommended to use with -s
P Prompt for Ansible vault passphrase (this is NOT the gaia admin user password)
h This help
EOF
}
while getopts c:skl:hIi:u:OP Opt; do
case $Opt in
h)
print_usage
exit 1
;;
i)
inventory=${OPTARG}
;;
l)
targets=${OPTARG}
;;
I)
ignore_errors=1
;;
k)
keep_script=1
;;
s)
save_output=1
;;
O)
show_output=0
;;
P)
vault_pass_prompt=1
;;
c)
clish_cmd="'${OPTARG}'"
;;
u)
gaia_admin_user="${OPTARG}"
;;
esac
done
if [ -z "${inventory}" ]; then
inventory=inventory.yml
fi
# Make output directory
rm -rf clish_output
install -d -m 0755 clish_output/
ansible-playbook \
-i ${inventory} \
$( (( "${vault_pass_prompt}" )) && echo "--ask-vault-pass" ) \
$( (( "${keep_script}" )) && echo "-e keep_script=true" ) \
$( [ -n "${gaia_admin_user}" ] && echo "-e gaia_admin_user=${gaia_admin_user}" ) \
run_clish_command.yml \
-e targets=${targets:-all} \
-e show_output=${show_output} \
-e save_output=${save_output} \
-e errors_ignored=${ignore_errors} \
-e clish_cmd="${clish_cmd}"
RET=$?
if (( $RET )); then
echo "Error ${RET} from ansible-playbook"
exit ${RET}
fi