espenak/awsfabrictasks — pull request #11 by imlucas (2013-06-10 21:33:47+00:00)
Title: Multitag Support

This also fixes the `@ec2instance` deco to behave like everything else.

New stuff:

Allow specifying multiple tags and region on `@ec2instance`

from fabric.api import task, env
from awsfabrictasks.decorators import ec2instance

@task
@ec2instance(tags={'Environment': 'production', 'Service Name': 'pythonapp'}, region='us-east-1')
def run_on_production_pythonapp_instances():
run('whoami')

Allow defining dynamically populated role defs. I find this to be a lot nicer than specifying key pairs to `--ec2tags` every time.

from fabric.api import task, env
from awsfabrictasks import expand_roledefs

env.roledefs.update({
'prod_web': {
'ec2:tagged': {
'Environment': 'production',
'Service Name': 'pythonapp',
'region': 'us-east-1'
}
},
'prod_celeryworkers': {
'ec2:tagged': {
'Environment': 'production',
'Service Name': 'worker',
'region': 'us-east-1'
}
},
'prod_celerybeat': {
'ec2:tagged': {
'Environment': 'production',
'Service Name': 'celerybeat',
'region': 'us-east-1'
}
},
'all_prod': {
'ec2:tagged': {
'Environment': 'production',
'region': 'us-east-1'
}
}
})

expand_roledefs()

@roles('prod_web')
def run_on_prod_pythonapp():
run('whoami')

@roles('prod_celeryworkers')
def restart_celeryworkers():
run('supervisorctl restart celery:celeryworkers:*')