Skip to content

Instantly share code, notes, and snippets.

@YellowSharkMT
Created November 29, 2016 00:23
Show Gist options
  • Save YellowSharkMT/8ecdf247fc502b88fe7b6c6ecfbd372d to your computer and use it in GitHub Desktop.
Save YellowSharkMT/8ecdf247fc502b88fe7b6c6ecfbd372d to your computer and use it in GitHub Desktop.
Simple example of a "new-style" Fabric task
# For reference, see:
# - http://docs.fabfile.org/en/1.12.0/usage/tasks.html#new-style-tasks
# - http://docs.fabfile.org/en/1.12.0/api/core/tasks.html
# - http://docs.fabfile.org/en/1.12.0/usage/execution.html#execute
from fabric.api import env, run, roles, execute
from fabric.tasks import Task
env.use_ssh_config = True
env.roledefs = {
"prod": ['server-1'],
"dev": ['server-2']
}
class MyTask(Task):
""" Description for MyTask... """
name = 'my_task'
def run(self, *args, **kwargs):
if 'dest' in kwargs:
execute(self.uname, roles=[kwargs['dest']])
else:
execute(self.uname)
@roles('prod')
def uname(self):
run('uname -a')
_ = MyTask()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment