Do multi-stage SSH with Fabric

Do multi-stage SSH with Fabric

I'm not familiar with it so I don't know the proper terminology, It is required when you want to log in to server 2 from the local via server 1 and operate it. This time, AWS has prepared a public subnet and a private subnet in the VPC, and I wanted to operate with fabric for the private subnet, so I will operate the instance in the private subnet via the instance in the public subnet. ..

Prerequisites

Since it was troublesome, both the server treated as a gateway and the server at the tunnel destination

will do. .. ..

script

It's a sample, so just ls -al ... host1 is the IP address of an instance in the public subnet. host2 is the IP address of an instance in the private subnet.

Set the processing target to the usual host, and write the endpoint of the tunnel destination in ʻenv.gateway`. ** That's it w **

fabfile.py


from fabric.api import env, run
from fabric.decorators import task, hosts

#Server settings
env.user = "username"
env.group = "group name"
env.key_filename = "Path to private key"
env.use_ssh_config = True

@task
@hosts("host1")
def sample_task():
    env.gateway = "host2"
    run("ls -al")

end

Recommended Posts

Do multi-stage SSH with Fabric
Until SSH connection with Fabric (MacOS-> CentOS7)
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Do Django with CodeStar (Python3.8, Django2.1.15)
Fast file transfer with fabric
Let's do R-CNN with Sklearn-theano
Do something fuzzing with acceptableRegex.py
Do not switch with pyenv global!
What to do with Magics install
To do tail recursion with Python2
What to do with PYTHON release?
Automation of remote operations with Fabric
Let's do image scraping with Python
I want to do ○○ with Pandas
I couldn't daemonize gunicorn with Fabric
Easy deployment environment with gaffer + fabric
Python | What you can do with Python