bundlewrap/bundles/postgresql/items.py
Franziska Kunsmann a160e7cf46
All checks were successful
bundlewrap/pipeline/head This commit looks good
bundles/postgresql: improvements
- support other postgresql versions
- manage configs using bw
2021-01-23 11:35:03 +01:00

90 lines
2.3 KiB
Python

postgresql_version = node.metadata['postgresql']['version']
pkg_apt = {
'postgresql-common': {},
'postgresql-client-common': {},
'postgresql-{}'.format(postgresql_version): {},
'postgresql-client-{}'.format(postgresql_version): {},
'postgresql-server-dev-{}'.format(postgresql_version): {},
}
if node.has_bundle('zfs'):
for pkgname, pkgconfig in pkg_apt.items():
pkg_apt[pkgname]['needs'] = {
'zfs_dataset:tank/postgresql',
}
directories = {
'/etc/postgresql': {
'owner': None,
'group': None,
'mode': None,
# Keeping old configs messes with cluster-auto-detection.
'purge': True,
},
# This is needed so the above purge does not remove the version
# currently installed.
'/etc/postgresql/{}'.format(postgresql_version): {
'owner': None,
'group': None,
'mode': None,
},
}
files = {
"/etc/postgresql/{}/main/pg_hba.conf".format(postgresql_version): {
'content_type': 'mako',
'owner': 'postgres',
'group': 'postgres',
'triggers': {
'svc_systemd:postgresql:restart',
},
},
"/etc/postgresql/{}/main/postgresql.conf".format(postgresql_version): {
'content_type': 'mako',
'context': node.metadata['postgresql'],
'owner': 'postgres',
'group': 'postgres',
'triggers': {
'svc_systemd:postgresql:restart',
},
},
}
postgres_roles = {
'root': {
'password': repo.vault.password_for('{} postgresql root'.format(node.name)),
'superuser': True,
'needs': {
'svc_systemd:postgresql',
},
},
}
svc_systemd = {
'postgresql': {
'needs': {
'pkg_apt:postgresql-11',
},
},
}
postgres_dbs = {}
for user, config in node.metadata.get('postgresql', {}).get('roles', {}).items():
postgres_roles[user] = {
'password': config['password'],
'needs': {
'svc_systemd:postgresql',
},
}
for database, config in node.metadata.get('postgresql', {}).get('databases', {}).items():
postgres_dbs[database] = {
'owner': config['owner'],
'needs': {
'postgres_role:',
'svc_systemd:postgresql',
},
}