Skip to content

Commit

Permalink
Factor out the Postgres role adding so other roles can be easily added.
Browse files Browse the repository at this point in the history
  • Loading branch information
KayEss committed Jun 19, 2013
1 parent e93ae59 commit 5ba46a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,3 +1,6 @@
2013-06-19 Kirit Saelensminde <kirit@felspar.com>
Factor out the Postgres role adding so other roles can be easily added.

2013-01-04 Kirit Saelensminde <kirit@felspar.com>
Fix the devenv script so that the profab paths are always first.
Handle the new format for the AMI web page so we can find the right ones.
Expand Down
21 changes: 16 additions & 5 deletions profab/role/postgres.py
Expand Up @@ -12,21 +12,32 @@ class AddRole(Role):
packages = ['postgresql']


@classmethod
def ident_user(cls, _server, username):
"""Make sure that the specified user name ihas a Postgres role
and user database.
"""
pguser = \
run('''psql -x -c "select * from pg_user where username='%s'"'''
% username)
if 'No rows' in pguser:
run('createuser -l -S -D -I -R %s' % username)
run('createdb -O %s -E UTF-8 %s' % (username, username))


def configure(self, server):
"""Configure Postgres once it is running.
"""
# The first user needs to be created using sudo
pguser = sudo('''psql -x -c "select * from pg_user '''
'''where usename='ubuntu'"''', user='postgres')
if 'No rows' in pguser:
sudo('psql -c "create role ubuntu login superuser"',
user='postgres')
sudo('psql -c "create database ubuntu with owner=ubuntu"',
user='postgres')
pguser = run('''psql -x -c "select * from pg_user where '''
'''usename='www-data'"''')
if 'No rows' in pguser:
run('createuser -l -S -D -I -R www-data')
run('createdb -O www-data -E UTF-8 www-data')
# Other users can be created generically
self.ident_user(server, 'www-data')

postgres_path = self.get_configuration_path('/etc/postgresql')
sed('%s/main/pg_hba.conf' % postgres_path,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -10,7 +10,7 @@ def read(fname1, fname2):

setup(
name = "profab",
version = "0.4.8",
version = "0.4.8.1",
author = "Proteus Technologies Infrastructure team",
author_email = "infrastructure@proteus-tech.com",
url = 'https://github.com/Proteus-tech/profab',
Expand Down

0 comments on commit 5ba46a9

Please sign in to comment.