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
|
||||
required: false
|
||||
default: null
|
||||
encoding:
|
||||
description:
|
||||
- Encoding of the database
|
||||
required: false
|
||||
default: null
|
||||
state:
|
||||
description:
|
||||
- The database state
|
||||
|
@ -143,7 +148,8 @@ def main():
|
|||
template=dict(default=""),
|
||||
encoding=dict(default=""),
|
||||
state=dict(default="present", choices=["absent", "present"]),
|
||||
)
|
||||
),
|
||||
supports_check_mode = True
|
||||
)
|
||||
|
||||
if not postgresqldb_found:
|
||||
|
@ -182,10 +188,15 @@ def main():
|
|||
module.fail_json(msg="unable to connect to database: %s" % e)
|
||||
|
||||
try:
|
||||
if module.check_mode:
|
||||
module.exit_json(changed=True,db=db)
|
||||
|
||||
if state == "absent":
|
||||
changed = db_delete(cursor, db)
|
||||
|
||||
elif state == "present":
|
||||
changed = db_create(cursor, db, owner, template, encoding)
|
||||
|
||||
except Exception, e:
|
||||
module.fail_json(msg="Database query failed: %s" % e)
|
||||
|
||||
|
|
|
@ -375,8 +375,10 @@ def main():
|
|||
port=dict(default='5432'),
|
||||
fail_on_user=dict(default='yes'),
|
||||
role_attr_flags=dict(default='')
|
||||
)
|
||||
),
|
||||
supports_check_mode = True
|
||||
)
|
||||
|
||||
user = module.params["user"]
|
||||
password = module.params["password"]
|
||||
state = module.params["state"]
|
||||
|
@ -412,17 +414,34 @@ def main():
|
|||
kw = dict(user=user)
|
||||
changed = False
|
||||
user_removed = False
|
||||
|
||||
if state == "present":
|
||||
|
||||
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)
|
||||
else:
|
||||
if password is None:
|
||||
msg = "password parameter required when adding a user"
|
||||
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 = grant_privileges(cursor, user, privs) or changed
|
||||
else:
|
||||
|
||||
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)
|
||||
user_removed = user_delete(cursor, user)
|
||||
changed = changed or user_removed
|
||||
|
|
Loading…
Reference in a new issue