How to discover current role in Python Fabric

前端 未结 5 384
既然无缘
既然无缘 2021-02-02 10:24

This is a very Fabric specific question, but more experienced python hackers might be able to answer this, even if they don\'t know Fabric.

I am trying to specify differ

5条回答
  •  情歌与酒
    2021-02-02 11:05

    For everyone else ever with this question, here is my solution:

    The key was finding env.host_string.

    This is how I restart different types of servers with one command:

    env.roledefs = {
        'apache': ['xxx.xxx.com'],
        'APE': ['yyy.xxx.com']
    }
    
    def apache():
        env.roles = ['apache']
    
    ...
    
    def restart():
        if env.host_string in env.roledefs['apache']:
            sudo("apache2ctl graceful", pty=True)
        elif env.host_string in env.roledefs['APE']:
            sudo ("supervisorctl reload", pty=True)
    

    enjoy!

提交回复
热议问题