2013年11月7日 星期四

Fabirc (2): @Task and @roles

Decorators:

We can use decorators to use a specific environment.

-use @task to separate task from general functions.  

For example. It you use command fab list to  list all command in below fabfile.  It will only display 

the functions with @task decorators .

##fabfile.py
from fabric.api import *
@task
def cmd(cmd):
        run(cmd)

def cmd2(cmd):
        run(cmd)
@task
def cmd3(cmd):
        run(cmd)
-use @roles to specify a task only can ran on which roles
#fabfile.py
env.hosts=[“192.168.1.1”,”aal.yourdomain.com"]
env.roledefs={“web":[“aal.yourdomain.com"],”ap":[“1.1.1.1"]}

And you can use decorators to specify which tasks are ran on which roles.

@roles(“web")
def apache():
    sudo("apt-get update")
    sudo("apt-get install -y apache2")

 

沒有留言:

如何下載Facebook 相簿跟影片

影片:透過chrome plug-in : Video Downloader for Facebook<sup>TM</sup> 相簿: 透過chrome plug-in : Tampermonkey 搭配script : Facebo...