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

 

沒有留言:

demo_article

使用 msty.app 和 Knowledge Stacks 建立個人知識庫系統 說明 嘗試利用local llm自動從文字檔轉成影音檔 利用AI自動對文件檔產生影音檔案 - YouTube 引言 在資訊爆炸的時代,我們每天接收大量的資訊,但如何有效地管理...