Created
November 29, 2016 00:23
-
-
Save YellowSharkMT/8ecdf247fc502b88fe7b6c6ecfbd372d to your computer and use it in GitHub Desktop.
Simple example of a "new-style" Fabric task
This file contains 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
# 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