mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Webfaction will create a default database user when db is created. For symmetry and repeatability, delete it when db is deleted. Add missing param to documentation.
This commit is contained in:
parent
03999b457a
commit
784b265e72
1 changed files with 34 additions and 14 deletions
|
@ -4,7 +4,7 @@
|
||||||
#
|
#
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
#
|
#
|
||||||
# (c) Quentin Stafford-Fraser 2015
|
# (c) Quentin Stafford-Fraser and Andy Baker 2015
|
||||||
#
|
#
|
||||||
# This file is part of Ansible
|
# This file is part of Ansible
|
||||||
#
|
#
|
||||||
|
@ -53,6 +53,12 @@ options:
|
||||||
required: true
|
required: true
|
||||||
choices: ['mysql', 'postgresql']
|
choices: ['mysql', 'postgresql']
|
||||||
|
|
||||||
|
password:
|
||||||
|
description:
|
||||||
|
- The password for the new database user.
|
||||||
|
required: false
|
||||||
|
default: None
|
||||||
|
|
||||||
login_name:
|
login_name:
|
||||||
description:
|
description:
|
||||||
- The webfaction account to use
|
- The webfaction account to use
|
||||||
|
@ -75,6 +81,10 @@ EXAMPLES = '''
|
||||||
type: mysql
|
type: mysql
|
||||||
login_name: "{{webfaction_user}}"
|
login_name: "{{webfaction_user}}"
|
||||||
login_password: "{{webfaction_passwd}}"
|
login_password: "{{webfaction_passwd}}"
|
||||||
|
|
||||||
|
# Note that, for symmetry's sake, deleting a database using
|
||||||
|
# 'state: absent' will also delete the matching user.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
|
@ -110,13 +120,17 @@ def main():
|
||||||
db_map = dict([(i['name'], i) for i in db_list])
|
db_map = dict([(i['name'], i) for i in db_list])
|
||||||
existing_db = db_map.get(db_name)
|
existing_db = db_map.get(db_name)
|
||||||
|
|
||||||
|
user_list = webfaction.list_db_users(session_id)
|
||||||
|
user_map = dict([(i['username'], i) for i in user_list])
|
||||||
|
existing_user = user_map.get(db_name)
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
# Here's where the real stuff happens
|
# Here's where the real stuff happens
|
||||||
|
|
||||||
if db_state == 'present':
|
if db_state == 'present':
|
||||||
|
|
||||||
# Does an app with this name already exist?
|
# Does an database with this name already exist?
|
||||||
if existing_db:
|
if existing_db:
|
||||||
# Yes, but of a different type - fail
|
# Yes, but of a different type - fail
|
||||||
if existing_db['db_type'] != db_type:
|
if existing_db['db_type'] != db_type:
|
||||||
|
@ -129,8 +143,8 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
# If this isn't a dry run, create the app
|
# If this isn't a dry run, create the db
|
||||||
# print positional_args
|
# and default user.
|
||||||
result.update(
|
result.update(
|
||||||
webfaction.create_db(
|
webfaction.create_db(
|
||||||
session_id, db_name, db_type, db_passwd
|
session_id, db_name, db_type, db_passwd
|
||||||
|
@ -139,17 +153,23 @@ def main():
|
||||||
|
|
||||||
elif db_state == 'absent':
|
elif db_state == 'absent':
|
||||||
|
|
||||||
# If the app's already not there, nothing changed.
|
# If this isn't a dry run...
|
||||||
if not existing_db:
|
|
||||||
module.exit_json(
|
|
||||||
changed = False,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
# If this isn't a dry run, delete the app
|
|
||||||
result.update(
|
if not (existing_db or existing_user):
|
||||||
webfaction.delete_db(session_id, db_name, db_type)
|
module.exit_json(changed = False,)
|
||||||
)
|
|
||||||
|
if existing_db:
|
||||||
|
# Delete the db if it exists
|
||||||
|
result.update(
|
||||||
|
webfaction.delete_db(session_id, db_name, db_type)
|
||||||
|
)
|
||||||
|
|
||||||
|
if existing_user:
|
||||||
|
# Delete the default db user if it exists
|
||||||
|
result.update(
|
||||||
|
webfaction.delete_db_user(session_id, db_name, db_type)
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Unknown state specified: {}".format(db_state))
|
module.fail_json(msg="Unknown state specified: {}".format(db_state))
|
||||||
|
|
Loading…
Reference in a new issue