mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Added state for managing postgres groups
This commit is contained in:
parent
87c7c44492
commit
0e2bd0bee0
@ -41,6 +41,7 @@ Full list of builtin state modules
|
||||
pkgrepo
|
||||
postgres_database
|
||||
postgres_user
|
||||
postgres_group
|
||||
rabbitmq_user
|
||||
rabbitmq_vhost
|
||||
rvm
|
||||
|
6
doc/ref/states/all/salt.states.postgres_group.rst
Normal file
6
doc/ref/states/all/salt.states.postgres_group.rst
Normal file
@ -0,0 +1,6 @@
|
||||
==========================
|
||||
salt.states.postgres_group
|
||||
==========================
|
||||
|
||||
.. automodule:: salt.states.postgres_group
|
||||
:members:
|
112
salt/states/postgres_group.py
Normal file
112
salt/states/postgres_group.py
Normal file
@ -0,0 +1,112 @@
|
||||
'''
|
||||
Management of PostgreSQL groups (roles).
|
||||
========================================
|
||||
|
||||
The postgres_group module is used to create and manage Postgres groups.
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
frank:
|
||||
postgres_group.present
|
||||
'''
|
||||
|
||||
def present(name,
|
||||
createdb=False,
|
||||
createuser=False,
|
||||
encrypted=False,
|
||||
superuser=False,
|
||||
replication=False,
|
||||
password=None,
|
||||
groups=None,
|
||||
runas=None):
|
||||
'''
|
||||
Ensure that the named group is present with the specified privileges
|
||||
|
||||
name
|
||||
The name of the group to manage
|
||||
|
||||
createdb
|
||||
Is the group allowed to create databases?
|
||||
|
||||
createuser
|
||||
Is the group allowed to create other users?
|
||||
|
||||
encrypted
|
||||
Should the password be encrypted in the system catalog?
|
||||
|
||||
superuser
|
||||
Should the new group be a "superuser"
|
||||
|
||||
replication
|
||||
Should the new group be allowed to initiate streaming replication
|
||||
|
||||
password
|
||||
The group's pasword
|
||||
|
||||
groups
|
||||
A string of comma seperated groups the group should be in
|
||||
|
||||
runas
|
||||
System user all operation should be preformed on behalf of
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': 'Group {0} is already present'.format(name)}
|
||||
|
||||
# check if user exists
|
||||
if __salt__['postgres.user_exists'](name, runas=runas):
|
||||
return ret
|
||||
|
||||
# The user is not present, make it!
|
||||
if __opts__['test']:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Group {0} is set to be created'.format(name)
|
||||
return ret
|
||||
if __salt__['postgres.group_create'](groupname=name,
|
||||
createdb=createdb,
|
||||
createuser=createuser,
|
||||
encrypted=encrypted,
|
||||
superuser=superuser,
|
||||
replication=replication,
|
||||
password=password,
|
||||
groups=groups,
|
||||
runas=runas):
|
||||
ret['comment'] = 'The group {0} has been created'.format(name)
|
||||
ret['changes'][name] = 'Present'
|
||||
else:
|
||||
ret['comment'] = 'Failed to create group {0}'.format(name)
|
||||
ret['result'] = False
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def absent(name, runas=None):
|
||||
'''
|
||||
Ensure that the named group is absent
|
||||
|
||||
name
|
||||
The groupname of the group to remove
|
||||
|
||||
runas
|
||||
System user all operation should be preformed on behalf of
|
||||
'''
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': ''}
|
||||
|
||||
# check if group exists and remove it
|
||||
if __salt__['postgres.user_exists'](name, runas=runas):
|
||||
if __opts__['test']:
|
||||
ret['result'] = None
|
||||
ret['comment'] = 'Group {0} is set to be removed'.format(name)
|
||||
return ret
|
||||
if __salt__['postgres.group_remove'](name, runas=runas):
|
||||
ret['comment'] = 'Group {0} has been removed'.format(name)
|
||||
ret['changes'][name] = 'Absent'
|
||||
return ret
|
||||
else:
|
||||
ret['comment'] = 'Group {0} is not present, so it cannot be removed'.format(name)
|
||||
|
||||
return ret
|
Loading…
Reference in New Issue
Block a user