setup, refactor and reword a few sections, especially related to the getopts and hosts file.

This commit is contained in:
2026-08-05 14:12:29 -07:00
parent dcf4b3d451
commit 94431dff43
+27 -19
View File
@@ -9,6 +9,14 @@ LOCAL=$DIR/local.yml
URL="https://git.hyperling.com/me/env-ansible" URL="https://git.hyperling.com/me/env-ansible"
BRANCH="main" 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" config_dir="/usr/local/etc/hyperling-scm"
general_config="$config_dir/general.ini" general_config="$config_dir/general.ini"
workstation_config="$config_dir/workstation.ini" workstation_config="$config_dir/workstation.ini"
@@ -46,10 +54,10 @@ while getopts ":lb:gwsfh" arg; do
case $arg in case $arg in
l) local="Y" && echo "Running $LOCAL as the playbook." ;; l) local="Y" && echo "Running $LOCAL as the playbook." ;;
b) branch="$OPTARG" && echo "Using branch $branch instead of $BRANCH." ;; b) branch="$OPTARG" && echo "Using branch $branch instead of $BRANCH." ;;
g) create_general="Y" && echo "Requested '$general_config'." ;; g) create_general="Y" && echo "Generating test '$general_config'." ;;
w) create_workstation="Y" && echo "Requested '$workstation_config'." ;; w) create_workstation="Y" && echo "Generating test '$workstation_config'." ;;
s) create_server="Y" && echo "Requested '$server_config'." ;; s) create_server="Y" && echo "Generating test '$server_config'." ;;
f) show_facts="Y" ;; f) show_facts="Y" && echo "Displaying ansible facts then exiting." ;;
h) usage ;; h) usage ;;
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;; *) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
esac 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 if [[ $os == *Debian* || $os == *Ubuntu* || $os == *"Pop!_OS"* || $os == *Mint* || $os == *Parrot* ]]; then
sudo apt update sudo apt update
sudo apt install -y ansible git <<< N 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 elif [[ $os == *FreeBSD* ]]; then
sudo pkg install -y -g py*-ansible git sudo pkg install -y -g py*-ansible git
sudo mkdir -p /usr/local/etc/ansible HOSTS_DIR="$FREEBSD_HOSTS_DIR"
sudo sh -c 'echo "localhost ansible_connection=local" > /usr/local/etc/ansible/hosts' HOSTS_FILE="$FREEBSD_HOSTS_FILE"
elif [[ $os == *Arch* || $os == *Manjaro* || $os == *Artix* ]]; then elif [[ $os == *Arch* || $os == *Manjaro* || $os == *Artix* ]]; then
sudo pacman -Sy --noconfirm ansible git 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 elif [[ $os == *Darwin* ]]; then
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo "TESTING - EXIT!"
exit 0
brew install ansible git brew install ansible git
HOSTS_DIR=""
HOSTS_FILE=""
elif [[ $os == *Fedora* ]]; then elif [[ $os == *Fedora* ]]; then
sudo dnf install -y ansible git python3-libselinux 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 elif [[ $os == *openSUSE* ]]; then
sudo zypper install -y ansible git 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 elif [[ $os == *NixOS* ]]; then
$DIR/files/scripts/nixos.sh -b $branch $DIR/files/scripts/nixos.sh -b $branch
sudo mkdir -p /etc/ansible
sudo sh -c 'echo "localhost ansible_connection=local" > /etc/ansible/hosts'
else else
echo -e "ERROR: OS not detected." echo -e "ERROR: OS not recognized."
echo -e "$os" echo -e "$os"
exit 1 exit 1
fi fi
fi fi
echo "Installed!" 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 if [[ "$show_facts" == "Y" ]]; then
echo "Showing Ansible Facts" echo "Showing Ansible Facts"
ansible localhost -m setup --connection=local ansible localhost -m setup --connection=local