Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change gateway settings not working #1375

Closed
pserrano opened this issue Sep 7, 2015 · 7 comments
Closed

Change gateway settings not working #1375

pserrano opened this issue Sep 7, 2015 · 7 comments

Comments

@pserrano
Copy link

pserrano commented Sep 7, 2015

Explain my problem.

I need to enter on two bastion server for supply a few script. And i use settings for add information to gateway variable for change address to the bastions servers.

def copy_live():
        with settings(gateway='root@l-bastion'):
def restore():
    with settings(gateway='root@q-bastion'):

if i make this:

def fulldeploy():
        execute(copy_live)
        execute(restore)

the variable for gateway don't modify the attribute for second setting and reconnect to live env and make all script exec on live again. But if only execute one def, works perfect.
I don't know if a bug or i have made a programming mistake.

@kaaveland
Copy link

Does it fix your problem if you 'invert' your settings?

def fulldeploy():
    with settings(gateway='root@l-bastion'):
        execute(copy_live)
    with settings(gateway='root@q-bastion'):
        execute(restore)

@pserrano
Copy link
Author

@kaaveland No, it isn't fix. Only connect on first gateway and don't disconnect for this if you want connect to other one on same execution. Fabric ignore this. It's very frustrating because many devops works with bastion models.

@kaaveland
Copy link

Yeah, we have the same model at work, but I've been able to do this in the past. If I recall correctly, I used some workaround (which is why I tried suggesting the above) and had it work fine, I'll take a look later (hopefully tonight) and see if I can find out how we actually dealt with this.

@pserrano
Copy link
Author

Nice @kaaveland, many thx! Now, i've fix it with execute 2 commands, but i want to be able on only one. it's a poor patch, but i've hope that your search to be successfully 💃

@kaaveland
Copy link

I was unable to find anything in our scripts for this, I had remembered a different gateway-related problem. I'm not longer sure I understand what you mean.

I have have the following servers: app-server-1, which is only reachable through bastion-1. And app-server-2, which is only reachable through bastion-2. app-server-1 can't reach app-server-2 and bastion-1 can't reach bastion-2. Is that correct?

I had assumed that you wanted to do something like move data from app-server-1 to app-server-2. So I made the following minimal fab-file:

from fabric.api import env, run, task, settings, execute, hosts

@hosts(['app-server-1'])
def get_info_1():
    with settings(gateway='bastion-1'):
        run("hostname")

@hosts(['app-server-2'])
def get_info_2():
    with settings(gateway='bastion-2'):
        run("hostname")

def full():
    execute(get_info_1)
    execute(get_info_2)

And that seems to work fine for me. I can execute this both as fab full and fab get_info_1 get_info_2. I can not actually reach the app-servers on anything other than the correct gateway-server, so I'd have gotten errors otherwise.

Have I misunderstood what your problem is? What do you want your program to look like?

@pserrano
Copy link
Author

I've found my mistake. I'm always using by default on my all fabric scripts this option

env.use_ssh_config = True

I've seen that if it's true, script access to .ssh/config for see if it have this login into file. And only connect to first site, and abort login on second one.

@kaaveland many thx for your support 👍

@kaaveland
Copy link

Cool, happy to see you solved your problem :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants