From 5ba46a9c45d360da75bc7774348bc67af10750b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirit=20S=C3=A6lensminde?= Date: Wed, 19 Jun 2013 14:49:20 +0700 Subject: [PATCH] Factor out the Postgres role adding so other roles can be easily added. --- ChangeLog | 3 +++ profab/role/postgres.py | 21 ++++++++++++++++----- setup.py | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4487e9c..39b3506 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2013-06-19 Kirit Saelensminde + Factor out the Postgres role adding so other roles can be easily added. + 2013-01-04 Kirit Saelensminde 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. diff --git a/profab/role/postgres.py b/profab/role/postgres.py index 20ae1ec..a6a9cb2 100644 --- a/profab/role/postgres.py +++ b/profab/role/postgres.py @@ -12,9 +12,23 @@ 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: @@ -22,11 +36,8 @@ def configure(self, server): 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, diff --git a/setup.py b/setup.py index bf64c87..af666ca 100644 --- a/setup.py +++ b/setup.py @@ -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',