def setup_postgres_user(userpwd, adminpwd): # set the postgres user password prompts = [] prompts += expect('Enter new UNIX password:'******'Retype new UNIX password:'******'passwd postgres') # set the postgres db user password sudo("sudo -u postgres psql -d template1 -c \"ALTER USER postgres WITH PASSWORD '%s';\"" % adminpwd) # generate an ssh-key sudo("ssh-keygen -t rsa -b 4096 -N \"\" -f ~postgres/.ssh/id_rsa", user="******")
def setup_postgres_user_connectivity(): if env.host == env.db_master: srcIp = env.db_master destIp = env.db_slave else: srcIp = env.db_slave destIp = env.db_master prompts = [] prompts += expect("Are you sure you want to continue connecting (yes/no)?", "yes") prompts += expect("postgres@%s's password:"******"ssh-copy-id -i ~postgres/.ssh/id_rsa.pub postgres@%s" % destIp, user="******")
def setup_postgres_user(userpwd, adminpwd): # set the postgres user password prompts = [] prompts += expect('Enter new UNIX password:'******'Retype new UNIX password:'******'passwd postgres') # set the postgres db user password sudo( "sudo -u postgres psql -d template1 -c \"ALTER USER postgres WITH PASSWORD '%s';\"" % adminpwd) # generate an ssh-key sudo("ssh-keygen -t rsa -b 4096 -N \"\" -f ~postgres/.ssh/id_rsa", user="******")
def _setup_postgres(): # start at boot filename = "/tmp/foo_%s" % _a_bit_of_random() sudo("cat /etc/rc.conf | grep -v postgresql > %s" % filename) sudo("echo 'postgresql_enable=\"YES\"' >> %s" % filename) sudo("mv %s /etc/rc.conf" % filename) # init the db sudo("/usr/local/etc/rc.d/postgresql initdb") #start the db sudo("/usr/local/etc/rc.d/postgresql start") # create the user prompts = [] prompts += expect("Enter password for new role:", DB_PASSWORD) prompts += expect("Enter it again:", DB_PASSWORD) with expecting(prompts): expectsudo("createuser -d -S -R -P %s" % DB_ADMIN, user="******")