Created
January 17, 2010 20:49
-
-
Save bitprophet/279573 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# | |
# Initial, naive version | |
# | |
from fabric.api import * | |
def _new_rpms(): | |
""" | |
Return local filenames for all "new" RPMs. | |
""" | |
return ['some', 'file', 'paths'] | |
@hosts('repository') | |
def update_repo(): | |
""" | |
Push some new RPMs from this workstation to the repository. | |
""" | |
for rpm in _new_rpms(): | |
put(rpm, '/path/to/repository/root/') | |
sudo('/usr/sbin/update_rpm_repo') | |
@hosts('client1', 'client2', 'client3') | |
def update_clients(): | |
""" | |
Ensure all new RPMs are installed, and update the DB. | |
""" | |
for rpm in _new_rpms(): | |
sudo('yum install %s' % rpm) | |
sudo('/path/to/db/update/script.sh') |
This file contains hidden or 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
# | |
# Version with some rollbacks | |
# | |
from fabric.api import * | |
def _new_rpms(): | |
""" | |
Return local filenames for all "new" RPMs. | |
""" | |
return ['some', 'file', 'paths'] | |
@hosts('repository') | |
def update_repo(): | |
""" | |
Push some new RPMs from this workstation to the repository. | |
""" | |
# With no error handling here, any problem will result in termination. | |
# If invoked as "fab update_repo update_clients", update_clients will NOT | |
# run at all. | |
for rpm in _new_rpms(): | |
put(rpm, '/path/to/repository/root/') | |
sudo('/usr/sbin/update_rpm_repo') | |
@hosts('client1', 'client2', 'client3') | |
def update_clients(): | |
""" | |
Ensure all new RPMs are installed, and update the DB. | |
""" | |
# Keep track of what RPMs have been installed on this host so far. | |
installed_rpms = [] | |
for rpm in _new_rpms(): | |
with settings(warn_only=True): | |
result = sudo('yum install %s' % rpm) | |
if result.failed: | |
# Rollback: uninstall earlier RPMs, then terminate. | |
for rpm in installed_rpms: | |
result = sudo('yum uninstall %s' % rpm) | |
if result.failed: | |
# Rollback failed; tell user to manually clean up. | |
print "Rollback failed on host %s!" % env.host_string | |
# Since we return here, any later hosts can still try to run. | |
# Change this to abort() to stop completely. | |
print "Installation of '%s' failed on host %s! Skipping." % ( | |
rpm, env.host_string) | |
return | |
else: | |
# Success: add to list of installed RPMs | |
installed_rpms.append(rpm) | |
with settings(warn_only=True): | |
result = sudo('/path/to/db/update/script.sh') | |
if result.failed: | |
# Rollback | |
print "DB update script failed on host %s! Skipping to next." % env.host_string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment