Fabric与SaltStack

两个工具我都在用,而且是搭配着用。

  • Fabric用来安装配置SaltStack客户端,执行SaltStack的长串命令;
  • SaltStack用来部署机器环境,更新代码,维护crontab,维护软件包。

你瞧

def buzz_engine_sls_test(target):  
    """ Deploy buzz engine for testing"""
    with lcd("/srv/salt/code/buzzMaster"):
        local('git fetch')  #从线上库pull代码
        local('git checkout %s' %(target,))
        local("cat .git/HEAD")
        local('sudo salt -L "bj-buzz-engine01"  state.sls buzz -v test=True')
def buzz_timer_start():  
    """ start buzz timer """
    local("sudo salt -E 'spider[0-1]\d|spider2[0-9]' service.start timer")
    local("sudo salt -E 'spider[0-1]\d|spider2[0-9]' service.status timer")
def sweibo_restart_no_wayback():  
    local("sudo salt -E 'spider0.*|spider2.*|spider1[0-3,8]' cmd.run '/etc/init.d/sweibo restart'")