-
-
Save boyobejamin/85f3dcc2ea9c2553d474 to your computer and use it in GitHub Desktop.
Ubuntu update manager for Fabric. Checks for updates, installs them and reboots if needed across multiple servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Ubuntu update manager for Fabric | |
Checks for updates, installs them and reboots if needed across multiple servers | |
Create a "hosts" file alongside this fabfile and put your hosts in there one per line | |
Updating package list:: | |
fab update | |
Check for updates:: | |
fab check | |
Install updates and reboot (if necessary):: | |
fab upgrade | |
""" | |
from fabric.api import sudo, run, env | |
from fabric.colors import red | |
from fabric.contrib.files import exists | |
from fabric.contrib.console import confirm | |
for host in open('hosts').readlines(): | |
host = host.strip() | |
if host.startswith('#'): | |
continue | |
env.hosts.append(host) | |
def update(): | |
""" | |
Updates the package list | |
""" | |
sudo('apt-get update -qq') | |
def check(): | |
""" | |
Displays package updates needed | |
""" | |
run("""apt-get dist-upgrade -s | python -c "import sys; [sys.stderr.write(l) for l in sys.stdin.readlines()[7:] if not (l.startswith('Inst') or l.startswith('Conf'))]" """) | |
def upgrade(): | |
""" | |
Upgrades the system, updating packages and reboots if needed | |
""" | |
sudo('apt-get -y upgrade') | |
if exists('/var/run/reboot-required') and confirm('Needs reboot, do it now?'): | |
print(red('Rebooting now', True)) | |
sudo('reboot') | |
def dist(): | |
""" | |
Upgrades the system, updating packages and reboots if needed | |
""" | |
sudo('apt-get -y dist-upgrade') | |
if exists('/var/run/reboot-required') and confirm('Needs reboot, do it now?'): | |
print(red('Rebooting now', True)) | |
sudo('reboot') | |
def autoclean(): | |
sudo('apt-get autoclean') | |
def autoremove(): | |
sudo('apt-get autoremove -y') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment