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. ..
Since it was troublesome, both the server treated as a gateway and the server at the tunnel destination
will do. .. ..
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