I'd like to run a Fabric command that would look something like this:
fab show_users:web01
where show_users would be defined like this:
def show_users(webserver):
if webserver == 'web01':
DB_NAME = 'db01'
elif webserver == 'web02':
DB_NAME = 'db02'
elif webserver == 'web03':
DB_NAME = 'db03'
else:
print "Error: invalid webserver."
cmd = "psql -h {0} -U <role> -d <database> -c 'SELECT id, username FROM auth_user;'".format(DB_NAME)
run(cmd)
When I run the command, I get this error:
No hosts found. Please specify (single) host string for connection: web01.
If I enter 'web01', which is defined in my /etc/hosts file, the command will then work. What is the correct way to do this?