From 66053db4624cd4cab9a18010ead55de434095f1f Mon Sep 17 00:00:00 2001 From: Greg Dumas Date: Mon, 18 Nov 2024 11:26:11 -0500 Subject: [PATCH 1/7] Install aws for ansible --- bin/install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/install.sh b/bin/install.sh index 04ff61c..8b6bf26 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -80,6 +80,10 @@ pip3 install boto boto3 --user pip3 install 'yq==2.10.0' --user +# install AWS collection for ansible +ansible-galaxy collection install amazon.aws + + echo "Before you can run Zathras:" echo "****Ensure ~/.local/bin is in your path" echo "****Set up a scenario file" From e1c957c647a893789b74944865e3d93414d69d09 Mon Sep 17 00:00:00 2001 From: Greg Dumas Date: Mon, 18 Nov 2024 13:13:02 -0500 Subject: [PATCH 2/7] Freeze terraform version --- bin/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install.sh b/bin/install.sh index 8b6bf26..77cd9a2 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -67,7 +67,7 @@ for package in "${packages[@]}"; do sudo dnf config-manager --add-repo $repo_url # install the package - sudo dnf install terraform -y + sudo dnf install terraform-1.9.8-1 -y else echo "package $package is not installed and not available." fi From b83f9832daa5d2920ac3b62b26bbe63438bce374 Mon Sep 17 00:00:00 2001 From: Greg Dumas Date: Thu, 12 Dec 2024 10:21:32 -0500 Subject: [PATCH 3/7] Add exit condition if packages are not available to install --- bin/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install.sh b/bin/install.sh index 77cd9a2..9fe153a 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -70,6 +70,7 @@ for package in "${packages[@]}"; do sudo dnf install terraform-1.9.8-1 -y else echo "package $package is not installed and not available." + exit 1 fi done From 3fb29591f124faa6c80cd1c1ac88b98209160804 Mon Sep 17 00:00:00 2001 From: Greg Dumas Date: Thu, 12 Dec 2024 10:46:02 -0500 Subject: [PATCH 4/7] Add error handling to dnf install commands --- bin/install.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/bin/install.sh b/bin/install.sh index 9fe153a..d64bd64 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -17,6 +17,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +set -eu + # Check if script is being run as root if (( $EUID == 0 )); then read -p "For most use cases, running this script as root is NOT recommended. Are you sure? Y/N" yesno @@ -39,9 +41,6 @@ packages=(ansible-core git jq python python3-pip terraform wget) for package in "${packages[@]}"; do if dnf list installed "$package" &> /dev/null; then echo "$package is installed." - elif dnf list "$package" &> /dev/null; then - echo "$package is not installed but available. Installing..." - sudo dnf install -y "$package" elif [ $package == "terraform" ]; then # Add the terraform repository from HashiCorp # currently supported distros: fedora, RHEL @@ -67,10 +66,14 @@ for package in "${packages[@]}"; do sudo dnf config-manager --add-repo $repo_url # install the package - sudo dnf install terraform-1.9.8-1 -y + sudo dnf install terraform-1.9.8-1 -y || { + exit 1 + } else - echo "package $package is not installed and not available." - exit 1 + echo "Installing $package..." + sudo dnf install -y "$package" || { + exit 1 + } fi done From 5ac170f8ad103a9d071f81bfe4fcb6dc24b98c22 Mon Sep 17 00:00:00 2001 From: Greg Dumas Date: Thu, 12 Dec 2024 10:47:39 -0500 Subject: [PATCH 5/7] Add space after prompt --- bin/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/install.sh b/bin/install.sh index d64bd64..a7b5912 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -21,7 +21,7 @@ set -eu # Check if script is being run as root if (( $EUID == 0 )); then - read -p "For most use cases, running this script as root is NOT recommended. Are you sure? Y/N" yesno + read -p "For most use cases, running this script as root is NOT recommended. Are you sure? Y/N " yesno case $yesno in [Yy]* ) From 1dab34ca783b4252cb85532637d74c3f495e7d68 Mon Sep 17 00:00:00 2001 From: Greg Dumas Date: Thu, 12 Dec 2024 16:52:04 -0500 Subject: [PATCH 6/7] Add error handling for pip3 install --- bin/install.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/install.sh b/bin/install.sh index a7b5912..a34f1fb 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -79,9 +79,14 @@ for package in "${packages[@]}"; do done + # pip install requirements -pip3 install boto boto3 --user -pip3 install 'yq==2.10.0' --user +python_packages=(boto boto3 'yq==2.10.0') +for package in "${python_packages[@]}"; do + pip3 install "$package" --user || { + exit 1 + } +done # install AWS collection for ansible From 39a53c87a7f64f6271cf87dd88ba9c5e57a24bc5 Mon Sep 17 00:00:00 2001 From: Greg Dumas Date: Thu, 12 Dec 2024 16:53:08 -0500 Subject: [PATCH 7/7] Add error handling for ansible-galaxy install --- bin/install.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/install.sh b/bin/install.sh index a34f1fb..361dc55 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -90,7 +90,12 @@ done # install AWS collection for ansible -ansible-galaxy collection install amazon.aws +ansible_collections=(amazon.aws) +for collection in "${ansible_collections[@]}"; do + ansible-galaxy collection install "$collection" || { + exit 1 + } +done echo "Before you can run Zathras:"