Reputation: 15288
I want to be able to log in to my AWS postgres database from a remote machine. I am using the following Fabric
script:
import sys
from fabric.api import env, run, abort
env.port = 123
env.use_ssh_config = True
def setuser(user):
"""Sets the ssh user for the fabric script"""
env.user = user
env.password = 'mypassword'
def setenv(server):
"""Sets the environment for the fabric script"""
env.hosts = ['staging']
def sync():
# log into AWS server
run("psql --host=staging.xxx.rds.amazonaws.com --username=x_user --port=5432 --password --dbname=x_database")
run("mypassword")
I run this Fabric
script using the following command:
fab -f sync_staging.py sync --password=mypassword
This logs me into the remote machine, runs the line run("psql ....
and then it prompts me for a password:
[stage] out: Password for user x_user:
Is there any way that I can supply the password (or respond to the prompt) such that it logs me in automatically?
Upvotes: 4
Views: 676
Reputation: 6423
There are 2 ways of solving this that I know of:
If you need to set an environment variable on remote host, use with shell_env(PGPASSWORD='mypassword')
, Fabric docs here: fabric.context_managers.shell_env
Hope it solves your problem.
Upvotes: 4