How to set target hosts in Fabric file

后端 未结 15 788
南方客
南方客 2020-11-29 15:27

I want to use Fabric to deploy my web app code to development, staging and production servers. My fabfile:

def deploy_2_dev():
  deploy(\'dev\')

def deploy_         


        
15条回答
  •  被撕碎了的回忆
    2020-11-29 15:52

    Using roles is currently considered to be the "proper" and "correct" way of doing this and is what you "should" do it.

    That said, if you are like most of what you "would like" or "desire" is the ability to perform a "twisted syster" or switching target systems on the fly.

    So for entertainment purposes only (!) the following example illustrates what many might consider to a risky, and yet somehow thoroughly satisfying, manoeuvre that goes something like this:

    env.remote_hosts       = env.hosts = ['10.0.1.6']
    env.remote_user        = env.user = 'bob'
    env.remote_password    = env.password = 'password1'
    env.remote_host_string = env.host_string
    
    env.local_hosts        = ['127.0.0.1']
    env.local_user         = 'mark'
    env.local_password     = 'password2'
    
    def perform_sumersault():
        env_local_host_string = env.host_string = env.local_user + '@' + env.local_hosts[0]
        env.password = env.local_password
        run("hostname -f")
        env.host_string = env.remote_host_string
        env.remote_password = env.password
        run("hostname -f")
    

    Then running:

    fab perform_sumersault
    

提交回复
热议问题