37. Deployment Options Fabric + Very simple, tasks are just Python functions + Easy to chain together tasks to create complex scripts out of bite size pieces - No source control integration - No out of box support - Some bugs, although fairly easy to work around, and new maintainer is working on fixes
59. Mapping Roles to Tasks # fabfile.py @roles('web') def uptime(): run('uptime') $> fab uptime [10.1.1.1] run: uptime [10.1.1.1] out: 05:20:39 up 88 days... [10.1.1.2] run: uptime [10.1.1.2] out: 05:20:39 up 88 days...
60.
61. Can't override decorated tasks at command line as docs suggestdef default_roles(*role_list): def selectively_attach(func): if not env.roles and not env.hosts: return roles(*role_list)(func) else: if env.hosts: func = hosts(*env.hosts)(func) if env.roles: func = roles(*env.roles)(func) return func return selectively_attach
62. All better now #fabfile.py @default_roles('web', 'db') def uptime(): run('uptime') $> fab uptime # runs on all hosts in the 'web' and 'db' roles $> fab uptime --roles lb # runs only on hosts in the 'lb' role
63.
64. Use a context manager when failures are anticipated# fabfile.py from __future__ import with_statement # py2.5 def symlink_me(): with settings(warn_only=True): run('rm /path/to/symlink') run('ln -s /home/andy /path/to/symlink')
65.
66. Great for sys-admin and one-off tasks# fabfile.py @default_roles('all') def invoke(command): "Invoke an arbritrary command" sudo(command) # install new packages on all hosts in one command $> fab invoke:"apt-get install git-core"
67. Real World Tasks $> fab --list Available commands: bounce_wsgi_procs Bounce the WSGI procs by touching the files deploy Full deployment deploy_media Push media to S3 invoke Invoke an arbritrary command migrate Run any migrations via South reload_nginx Update Nginx's running config splash_off Configure Nginx to serve the site splash_on Configure Nginx to serve a downed-site page update_repositories Push code to servers update_dependencies Update dependencies to third party libs
68. Whiskey's Deployment def deploy(splash='no'): "Full deployment" deploy_media() update_cached_repositories() update_dependencies() generate_releases() if splash == 'yes': splash_on() _symlink_code() migrate() bounce_wsgi_procs() if splash == 'yes': splash_off() $> fab deploy:splash=yes