Skip to content

Commit

Permalink
Make the ansible scripts a little safer.
Browse files Browse the repository at this point in the history
Context: Andrew mentioned it's possible to deploy to prod accidentally too easily, and I agree.

I updated the script to prompt for confirmation first, to make it a little safer.
  • Loading branch information
steventrouble committed Nov 8, 2023
1 parent 1035a33 commit 8ffe384
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ansible/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ while getopts 'h?l:Hvdp:' opt; do
;;
p) playbook=$OPTARG
;;
y) force=1
;;
esac
done

Expand All @@ -73,6 +75,21 @@ target="$2"
[[ "$target" == "eval" || "$target" == "prod" || "$target" == "targets" ]] || usage
[[ "$target" != "targets" ]] || targets
[[ -z $playbook ]] && playbook="install-${product}.yml"

if [[ $target =~ "prod" && force -eq 0 ]]
then
target=
read -p "Are you sure you want to push prod? [yN] " -r -n1
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
target="prod"
else
echo "Aborting"
exit 1
fi
fi

echo "Installing $playbook to $target"
[[ -r $playbook ]] || {
echo "Playbook $playbook not found!"
Expand Down Expand Up @@ -114,7 +131,7 @@ END
}


# run the installer
# run the installer

vars=
(( verb>0 )) && vars="$vars -v "
Expand All @@ -124,4 +141,3 @@ vars=
vars="$vars -l $limit "
}
ansible-playbook ${playbook} $vars -i ./hosts --extra-vars "target=${target}"

0 comments on commit 8ffe384

Please sign in to comment.