setup, refactor and reword a few sections, especially related to the getopts and hosts file.
This commit is contained in:
@@ -9,6 +9,14 @@ LOCAL=$DIR/local.yml
|
||||
URL="https://git.hyperling.com/me/env-ansible"
|
||||
BRANCH="main"
|
||||
|
||||
LINUX_HOSTS_DIR=/etc/ansible
|
||||
LINUX_HOSTS_FILE="$LINUX_HOSTS_DIR/hosts"
|
||||
FREEBSD_HOSTS_DIR="/usr/local/etc/ansible"
|
||||
FREEBSD_HOSTS_FILE="$FREEBSD_HOSTS_DIR/hosts"
|
||||
|
||||
HOSTS_DIR="$LINUX_HOSTS_DIR"
|
||||
HOSTS_FILE="$LINUX_HOSTS_FILE"
|
||||
|
||||
config_dir="/usr/local/etc/hyperling-scm"
|
||||
general_config="$config_dir/general.ini"
|
||||
workstation_config="$config_dir/workstation.ini"
|
||||
@@ -46,10 +54,10 @@ while getopts ":lb:gwsfh" arg; do
|
||||
case $arg in
|
||||
l) local="Y" && echo "Running $LOCAL as the playbook." ;;
|
||||
b) branch="$OPTARG" && echo "Using branch $branch instead of $BRANCH." ;;
|
||||
g) create_general="Y" && echo "Requested '$general_config'." ;;
|
||||
w) create_workstation="Y" && echo "Requested '$workstation_config'." ;;
|
||||
s) create_server="Y" && echo "Requested '$server_config'." ;;
|
||||
f) show_facts="Y" ;;
|
||||
g) create_general="Y" && echo "Generating test '$general_config'." ;;
|
||||
w) create_workstation="Y" && echo "Generating test '$workstation_config'." ;;
|
||||
s) create_server="Y" && echo "Generating test '$server_config'." ;;
|
||||
f) show_facts="Y" && echo "Displaying ansible facts then exiting." ;;
|
||||
h) usage ;;
|
||||
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
|
||||
esac
|
||||
@@ -97,41 +105,41 @@ if [[ `which ansible > /dev/null; echo $?` != 0 ]]; then
|
||||
if [[ $os == *Debian* || $os == *Ubuntu* || $os == *"Pop!_OS"* || $os == *Mint* || $os == *Parrot* ]]; then
|
||||
sudo apt update
|
||||
sudo apt install -y ansible git <<< N
|
||||
sudo mkdir -p /etc/ansible
|
||||
sudo sh -c 'echo "localhost ansible_connection=local" > /etc/ansible/hosts'
|
||||
elif [[ $os == *FreeBSD* ]]; then
|
||||
sudo pkg install -y -g py*-ansible git
|
||||
sudo mkdir -p /usr/local/etc/ansible
|
||||
sudo sh -c 'echo "localhost ansible_connection=local" > /usr/local/etc/ansible/hosts'
|
||||
HOSTS_DIR="$FREEBSD_HOSTS_DIR"
|
||||
HOSTS_FILE="$FREEBSD_HOSTS_FILE"
|
||||
elif [[ $os == *Arch* || $os == *Manjaro* || $os == *Artix* ]]; then
|
||||
sudo pacman -Sy --noconfirm ansible git
|
||||
sudo mkdir -p /etc/ansible
|
||||
sudo sh -c 'echo "localhost ansible_connection=local" > /etc/ansible/hosts'
|
||||
elif [[ $os == *Darwin* ]]; then
|
||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
echo "TESTING - EXIT!"
|
||||
exit 0
|
||||
brew install ansible git
|
||||
HOSTS_DIR=""
|
||||
HOSTS_FILE=""
|
||||
elif [[ $os == *Fedora* ]]; then
|
||||
sudo dnf install -y ansible git python3-libselinux
|
||||
sudo mkdir -p /etc/ansible
|
||||
sudo sh -c 'echo "localhost ansible_connection=local" > /etc/ansible/hosts'
|
||||
elif [[ $os == *openSUSE* ]]; then
|
||||
sudo zypper install -y ansible git
|
||||
sudo mkdir -p /etc/ansible
|
||||
sudo sh -c 'echo "localhost ansible_connection=local" > /etc/ansible/hosts'
|
||||
elif [[ $os == *NixOS* ]]; then
|
||||
$DIR/files/scripts/nixos.sh -b $branch
|
||||
sudo mkdir -p /etc/ansible
|
||||
sudo sh -c 'echo "localhost ansible_connection=local" > /etc/ansible/hosts'
|
||||
else
|
||||
echo -e "ERROR: OS not detected."
|
||||
echo -e "ERROR: OS not recognized."
|
||||
echo -e "$os"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
echo "Installed!"
|
||||
|
||||
if [[ -n $HOSTS_DIR && -n $HOSTS_FILE ]]; then
|
||||
echo "Ensuring hosts file exists..."
|
||||
if [[ ! -e $HOSTS_FILE ]]; then
|
||||
sudo mkdir -pv $HOSTS_DIR
|
||||
sudo sh -c "echo 'localhost ansible_connection=local' > $HOSTS_FILE"
|
||||
fi
|
||||
echo "$HOSTS_FILE: '`cat $HOSTS_FILE`'"
|
||||
echo "Hosts file created successfully!"
|
||||
fi
|
||||
|
||||
if [[ "$show_facts" == "Y" ]]; then
|
||||
echo "Showing Ansible Facts"
|
||||
ansible localhost -m setup --connection=local
|
||||
|
||||
Reference in New Issue
Block a user