Skip to content

Instantly share code, notes, and snippets.

@lgaggini
Forked from justquick/fabfile.py
Last active August 29, 2015 14:07
Show Gist options
  • Save lgaggini/2be3c5bb47b8ce9267bd to your computer and use it in GitHub Desktop.
Save lgaggini/2be3c5bb47b8ce9267bd to your computer and use it in GitHub Desktop.
Fabfile to manage apt-get updates on multiple machines, with or without confirms required
"""
Ubuntu update manager for Fabric
Checks for updates, installs them 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 with required confirms::
fab upgrade
Install updates without required confirms::
fab unattended_upgrade
Autoremove unused packages with required confirms::
fab autoremove
Autoremove unused packages without required confirms::
fab unattended_autoremove
Clean packages cache without required confirms::
fab clean
Full machines packages mantaineance with required confirms::
fab full
Full machines package mantaineance without required confirms::
fab unattended_full
"""
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'):
env.user = 'libersoft'
env.password = 'password'
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 upgrade')
def unattended_upgrade():
"""
Upgrades the system, updating packages and reboots if needed
"""
sudo('apt-get -y upgrade')
def autoremove():
"""
Autoremove unused package
"""
sudo('apt-get autoremove')
def unattended_autoremove():
"""
Autoremove unused package
"""
sudo('apt-get -y autoremove')
def clean():
"""
Clean package cache
"""
sudo('apt-get clean')
sudo('apt-get autoclean')
def full():
"""
Full machines packages mantaineance
"""
update()
upgrade()
autoremove()
clean()
def unattended_full():
"""
Full machines package mantaineance without required confirms
"""
update()
unattended_upgrade()
unattended_autoremove()
clean()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment