Reputation: 183
I want to create a database user for my setup fabric script but createuser has interactive password entering and seams not to like fabric.
Upvotes: 18
Views: 4050
Reputation: 2658
To extend the answer with a Fabric example...
# In fabfile.py
def create_database():
"""Creates role and database"""
db_user = get_user() # define these
db_pass = get_pass()
db_name = get_db_name()
sudo('psql -c "CREATE USER %s WITH NOCREATEDB NOCREATEUSER " \
"ENCRYPTED PASSWORD E\'%s\'"' % (db_user, db_pass), user='postgres')
sudo('psql -c "CREATE DATABASE %s WITH OWNER %s"' % (
db_name, db_user), user='postgres')
Upvotes: 35
Reputation: 11059
This is probably of some use without having to write your own modules or you could use it as reference.
from fabtools import require
require.postgres.create_db ???
Upvotes: 1
Reputation: 127396
Just use plain SQL to create a new user:
CREATE ROLE user_name WITH ENCRYPTED PASSWORD 'your password';
Upvotes: 8