mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add postgresql_db and postgresql_use checkmode.
This commit is contained in:
parent
6d604469d8
commit
621eb5eccc
2 changed files with 32 additions and 2 deletions
|
@ -59,6 +59,11 @@ options:
|
||||||
- Encoding of the database
|
- Encoding of the database
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
|
encoding:
|
||||||
|
description:
|
||||||
|
- Encoding of the database
|
||||||
|
required: false
|
||||||
|
default: null
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- The database state
|
- The database state
|
||||||
|
@ -143,7 +148,8 @@ def main():
|
||||||
template=dict(default=""),
|
template=dict(default=""),
|
||||||
encoding=dict(default=""),
|
encoding=dict(default=""),
|
||||||
state=dict(default="present", choices=["absent", "present"]),
|
state=dict(default="present", choices=["absent", "present"]),
|
||||||
)
|
),
|
||||||
|
supports_check_mode = True
|
||||||
)
|
)
|
||||||
|
|
||||||
if not postgresqldb_found:
|
if not postgresqldb_found:
|
||||||
|
@ -182,10 +188,15 @@ def main():
|
||||||
module.fail_json(msg="unable to connect to database: %s" % e)
|
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if module.check_mode:
|
||||||
|
module.exit_json(changed=True,db=db)
|
||||||
|
|
||||||
if state == "absent":
|
if state == "absent":
|
||||||
changed = db_delete(cursor, db)
|
changed = db_delete(cursor, db)
|
||||||
|
|
||||||
elif state == "present":
|
elif state == "present":
|
||||||
changed = db_create(cursor, db, owner, template, encoding)
|
changed = db_create(cursor, db, owner, template, encoding)
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
module.fail_json(msg="Database query failed: %s" % e)
|
module.fail_json(msg="Database query failed: %s" % e)
|
||||||
|
|
||||||
|
|
|
@ -375,8 +375,10 @@ def main():
|
||||||
port=dict(default='5432'),
|
port=dict(default='5432'),
|
||||||
fail_on_user=dict(default='yes'),
|
fail_on_user=dict(default='yes'),
|
||||||
role_attr_flags=dict(default='')
|
role_attr_flags=dict(default='')
|
||||||
|
),
|
||||||
|
supports_check_mode = True
|
||||||
)
|
)
|
||||||
)
|
|
||||||
user = module.params["user"]
|
user = module.params["user"]
|
||||||
password = module.params["password"]
|
password = module.params["password"]
|
||||||
state = module.params["state"]
|
state = module.params["state"]
|
||||||
|
@ -412,17 +414,34 @@ def main():
|
||||||
kw = dict(user=user)
|
kw = dict(user=user)
|
||||||
changed = False
|
changed = False
|
||||||
user_removed = False
|
user_removed = False
|
||||||
|
|
||||||
if state == "present":
|
if state == "present":
|
||||||
|
|
||||||
if user_exists(cursor, user):
|
if user_exists(cursor, user):
|
||||||
|
if module.check_mode:
|
||||||
|
kw['changed'] = True
|
||||||
|
module.exit_json(**kw)
|
||||||
|
|
||||||
changed = user_alter(cursor, user, password, role_attr_flags)
|
changed = user_alter(cursor, user, password, role_attr_flags)
|
||||||
else:
|
else:
|
||||||
if password is None:
|
if password is None:
|
||||||
msg = "password parameter required when adding a user"
|
msg = "password parameter required when adding a user"
|
||||||
module.fail_json(msg=msg)
|
module.fail_json(msg=msg)
|
||||||
|
|
||||||
|
if module.check_mode:
|
||||||
|
kw['changed'] = True
|
||||||
|
module.exit_json(**kw)
|
||||||
|
|
||||||
changed = user_add(cursor, user, password, role_attr_flags)
|
changed = user_add(cursor, user, password, role_attr_flags)
|
||||||
changed = grant_privileges(cursor, user, privs) or changed
|
changed = grant_privileges(cursor, user, privs) or changed
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if user_exists(cursor, user):
|
if user_exists(cursor, user):
|
||||||
|
if module.check_mode:
|
||||||
|
kw['changed'] = True
|
||||||
|
kw['user_removed'] = True
|
||||||
|
module.exit_json(**kw)
|
||||||
|
|
||||||
changed = revoke_privileges(cursor, user, privs)
|
changed = revoke_privileges(cursor, user, privs)
|
||||||
user_removed = user_delete(cursor, user)
|
user_removed = user_delete(cursor, user)
|
||||||
changed = changed or user_removed
|
changed = changed or user_removed
|
||||||
|
|
Loading…
Reference in a new issue