2017-06-09 23:25:56 +00:00
#!/bin/bash
2017-10-30 17:57:55 +00:00
# running from a git repo
# ansible files exist
2017-10-24 16:39:49 +00:00
CWD=`pwd`
2017-10-30 17:57:55 +00:00
export ANSIBLE_LOG_PATH="$CWD/iiab-network.log"
2017-10-24 16:39:49 +00:00
2017-12-05 15:33:35 +00:00
if [ ! -f iiab-network.yml ]; then
2017-12-12 06:17:12 +00:00
echo "iiab-network.yml not found in current directory."
echo "Please rerun this command from the top level of the git repo."
2017-12-05 15:33:35 +00:00
echo "Exiting."
exit 1
2017-06-09 23:25:56 +00:00
fi
2017-12-05 15:33:35 +00:00
if [ ! -f /etc/iiab/config_vars.yml ]; then
2017-12-13 08:56:22 +00:00
echo "Creating stub /etc/iiab/config_vars.yml"
2017-12-05 15:33:35 +00:00
mkdir -p /etc/iiab
echo "{}" > /etc/iiab/config_vars.yml
fi
2017-12-07 23:56:22 +00:00
OS="unknown" # will be overridden below, if /etc/iiab/iiab.env is legit
2017-12-05 15:33:35 +00:00
if [ -f /etc/iiab/iiab.env ]; then
2018-04-09 00:57:49 +00:00
echo "Reading /etc/iiab/iiab.env"
2017-12-05 15:33:35 +00:00
source /etc/iiab/iiab.env
2017-06-09 23:25:56 +00:00
fi
2018-04-09 00:57:49 +00:00
echo "Ansible will now run iiab-network.yml -- log file is iiab-network.log"
2017-09-13 11:07:25 +00:00
Start=`date`
2019-10-28 03:16:10 +00:00
ansible -m setup -i ansible_hosts localhost --connection=local -e ansible_python_interpreter=/usr/bin/python3 | grep python
ansible-playbook -i ansible_hosts iiab-network.yml --connection=local -e ansible_python_interpreter=/usr/bin/python3
2017-09-15 16:56:57 +00:00
End=`date`
2017-12-07 23:48:35 +00:00
2017-12-13 08:56:22 +00:00
2017-12-07 23:56:22 +00:00
# Record critical diagnostics to [/opt/iiab/iiab/]iiab-network.log
2017-12-29 07:25:06 +00:00
echo >> iiab-network.log
2017-12-13 08:56:22 +00:00
2017-12-05 15:33:35 +00:00
# redhat path
2017-12-13 08:56:22 +00:00
# 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.
2017-12-13 08:15:39 +00:00
if [ "$OS" == "centos" ] || [ "$OS" == "fedora" ]; then
2017-12-07 23:48:35 +00:00
ls -la /etc/sys*/net*/ifcfg* >> iiab-network.log
2017-12-05 15:33:35 +00:00
fi
2017-12-13 07:57:26 +00:00
2017-12-13 08:56:22 +00:00
# Ubuntu desktop/others might be using NM (NetworkManager) - split out.
2017-12-13 11:34:12 +00:00
#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"
2017-12-07 23:48:35 +00:00
nmcli d >> iiab-network.log
2017-12-13 12:19:44 +00:00
echo >> iiab-network.log
2017-12-07 23:48:35 +00:00
nmcli c >> iiab-network.log
2017-06-09 23:25:56 +00:00
fi
2017-12-13 08:56:22 +00:00
2017-09-15 16:56:57 +00:00
ip r >> iiab-network.log
2017-12-07 23:19:19 +00:00
brctl show >> iiab-network.log
2017-12-13 12:19:44 +00:00
echo >> iiab-network.log
2017-12-13 12:25:23 +00:00
echo "iiab-network run start: $Start" >> iiab-network.log
echo "iiab-network run end: $End" >> iiab-network.log
2017-12-13 12:19:44 +00:00
echo >> iiab-network.log
echo >> iiab-network.log
2017-12-07 23:48:35 +00:00
2017-12-13 08:56:22 +00:00
2017-12-07 23:56:22 +00:00
# Put the same diagnostics on screen, for live operator
2017-12-13 11:36:29 +00:00
if [[ `command -v nmcli` ]]; then
2017-12-13 08:56:22 +00:00
nmcli d
2017-12-13 12:19:44 +00:00
echo
2017-12-13 08:56:22 +00:00
nmcli c
fi
2017-09-15 16:56:57 +00:00
ip r
2017-12-07 23:19:19 +00:00
brctl show
2017-12-13 12:19:44 +00:00
echo
2017-12-13 12:25:23 +00:00
echo "iiab-network run start: $Start"
echo "iiab-network run end: $End"