forked from georgejhunt/iiab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iiab-network
executable file
·75 lines (64 loc) · 2.7 KB
/
iiab-network
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
#!/bin/bash
# running from a git repo
# ansible files exist
CWD=`pwd`
export ANSIBLE_LOG_PATH="$CWD/iiab-network.log"
if [ ! -f iiab-network.yml ]; then
echo "iiab-network.yml not found in current directory."
echo "Please rerun this command from the top level of the git repo."
echo "Exiting."
exit 1
fi
if [ ! -f /etc/iiab/config_vars.yml ]; then
echo "Creating stub /etc/iiab/config_vars.yml"
mkdir -p /etc/iiab
echo "{}" > /etc/iiab/config_vars.yml
fi
OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit
if [ -f /etc/iiab/iiab.env ]; then
echo "Reading /etc/iiab/iiab.env"
source /etc/iiab/iiab.env
fi
echo "Ansible will now run iiab-network.yml -- log file is iiab-network.log"
Start=`date`
ansible-playbook -i ansible_hosts iiab-network.yml --connection=local
End=`date`
# Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log
echo >> iiab-network.log
# redhat path
# Paul Armstrong's Shell Style Guide (https://google.github.io/styleguide/shell.xml)
# prefers "if [[ ... ]]; then" for REGEXP's. Many others prefer "if [ ... ];" then.
# Each approach is sometimes necessary in my experience, working differently indeed.
if [ "$OS" == "centos" ] || [ "$OS" == "fedora" ]; then
ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log
fi
# Ubuntu desktop/others might be using NM (NetworkManager) - split out.
#if [ $(grep ubuntu /etc/apt/sources.list) ]; then # FAILS when multiple lines returned, due to single square brackets
#if grep -q ubuntu /etc/apt/sources.list ; then # Works: bypasses need for "> /dev/null" thanks to "grep -q" (quiet)
#if command -v nmcli > /dev/null ; then # Works But Wordy!
#if [[ $(command -v nmcli) ]]; then # Also Works! $(...) nests more easily than backticks
#if [[ `which nmcli` ]]; then # "which" misses built-in commands like cd, and is RISKY per https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
#if [[ `type -P nmcli` ]]; then # "type -P" isn't POSIX compliant; it misses built-in commands like "cd"
if [[ `command -v nmcli` ]]; then # "command -v" is POSIX compliant; it catches built-in commands like "cd"
nmcli d >> iiab-network.log
echo >> iiab-network.log
nmcli c >> iiab-network.log
fi
ip r >> iiab-network.log
brctl show >> iiab-network.log
echo >> iiab-network.log
echo "iiab-network run start: $Start" >> iiab-network.log
echo "iiab-network run end: $End" >> iiab-network.log
echo >> iiab-network.log
echo >> iiab-network.log
# Put the same diagnostics on screen, for live operator
if [[ `command -v nmcli` ]]; then
nmcli d
echo
nmcli c
fi
ip r
brctl show
echo
echo "iiab-network run start: $Start"
echo "iiab-network run end: $End"