Skip to content

Instantly share code, notes, and snippets.

@yatesr
Created October 18, 2013 15:02
Show Gist options
  • Save yatesr/7042886 to your computer and use it in GitHub Desktop.
Save yatesr/7042886 to your computer and use it in GitHub Desktop.
Ansible script for updating prod boxes (WIP)
#!/bin/bash
## updateprod.sh
# Updated: 2013-10-18
# Tested with: Ubuntu 12.04 x64
# Description: Script for updating production machines using ansible
# This script assumes that production machines are defined at /etc/ansible/hosts under [prod]
# The script will first use ansible with --check to show packages that will be updated and then prompt the user to continue with updating by entering (y)es or exit and NOT update packages by entering (n)o or anything else besides y. This also uses the current logged in user and the public/private key for authentication to each machine.
##
echo "Running ansible with --check..."
ansible prod -m apt -a "update_cache=yes upgrade=yes" --sudo --check
read -n1 -p "Upgrade packages on prod? [y,n]" UPGRADE
if [ "$UPGRADE" == "y" ]; then
echo -e "\nUpgrading..."
ansible prod -m apt -a "update_cache=yes upgrade=yes" --sudo
echo -e "\nUpgrade Complete!"
exit 1
else
echo -e "\nAborting..."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment