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")

 

沒有留言:

How to restore a deleted onenote page

復原不小心誤刪的onenote