Frage

I would like to deploy an application using fabric to a proxied server. Normally we ssh to a proxy server then ssh to the production server, however fabric doesn’t seem to allow for this directly.

An example of the setup would be local --> server A (Proxy) --> Server B (App server)

The destination is server B.

I have tried using the fab file below to test.

import os.path
from fabric.api import env, run, sudo, cd, local, put, settings
from fabric.contrib.files import sed, exists
from datetime import datetime

def proxy():
    env.user = "root"
    env.hosts = ['proxy']
    env.key_filename = "/home/root/monitorserver.pem"

def production():
    """Defines production environment ."""
    env.is_debuggable = False
    env.user = "root"
    env.hosts = ['appserver']
    env.key_filename = "/home/root/appserver.pem"

def createfile():
    """Start Excecute test commands"""
    sudo("touch /tmp/test_%s" % datetime.now().strftime('%H:%M:%S'))

but running the commands

fab proxy createfile production createfile

only seems to work as

fab proxy createfile
fab production createfile

Is there a way I can run fabric locally and deploy to server B with the proxy in place?

War es hilfreich?

Lösung

I think this can be done by creating 2 fabfiles: 1 on local, and 1 on the proxy server.

from fabric.api import env, run, sudo, cd
from datetime import datetime

def proxy():
    env.user = "root"
    env.hosts = ['proxy']
    env.key_filename = "/home/root/monitorserver.pem"
    with cd('/home/root/'):
        createfile()
        run("fab production")

def production():
    """Defines production environment ."""
    env.is_debuggable = False
    env.user = "root"
    env.hosts = ['appserver']
    env.key_filename = "/home/root/appserver.pem"
    createfile()

def createfile():
    """Start Excecute test commands"""
    sudo("touch /tmp/test_%s" % datetime.now().strftime('%H:%M:%S'))

Run fab proxy.

(Haven't tested the code, but something like this should work.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top