@ -41,10 +41,11 @@ options:
aliases: []
aliases: []
db_engine:
db_engine:
description:
description:
- The type of database. Used only when command=create. Must be one of: MySQL | oracle-se1 | oracle-se | oracle-ee | sqlserver-ee | sqlserver-se | sqlserver-ex | sqlserver-web
- The type of database. Used only when command=create.
required: false
required: false
default: null
default: null
aliases: []
aliases: []
choices: [ 'MySQL', 'oracle-se1', 'oracle-se', 'oracle-ee', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' ]
size:
size:
description:
description:
- Size in gigabytes of the initial storage for the DB instance. Used only when command=create or command=modify.
- Size in gigabytes of the initial storage for the DB instance. Used only when command=create or command=modify.
@ -53,10 +54,11 @@ options:
aliases: []
aliases: []
instance_type:
instance_type:
description:
description:
- The instance type of the database. Must be specified when command=create. Optional when command=replicate or command=modify. If not specified then the replica inherits the same instance type as the source instance. Must be one of: db.t1.micro | db.m1.small | db.m1.medium | db.m1.large | db.m1.xlarge | db.m2.xlarge | db.m2.2xlarge | db.m2.4xlarge
- The instance type of the database. Must be specified when command=create. Optional when command=replicate or command=modify. If not specified then the replica inherits the same instance type as the source instance.
required: false
required: false
default: null
default: null
aliases: []
aliases: []
choices: [ 'db.t1.micro', 'db.m1.small', 'db.m1.medium', 'db.m1.large', 'db.m1.xlarge', 'db.m2.xlarge', 'db.m2.2xlarge', 'db.m2.4xlarge' ]
username:
username:
description:
description:
- Master database username. Used only when command=create.
- Master database username. Used only when command=create.
@ -95,13 +97,15 @@ options:
aliases: []
aliases: []
license_model:
license_model:
description:
description:
- The license model for this DB instance. Used only when command=create. Must be one of: license-included | bring-your-own-license | general-public-license
- The license model for this DB instance. Used only when command=create.
required: false
required: false
default: null
default: null
aliases: []
aliases: []
choices: [ 'license-included', 'bring-your-own-license', 'general-public-license' ]
multi_zone:
multi_zone:
description:
description:
- Specifies if this is a Multi-availability-zone deployment. Can not be used in conjunction with zone parameter. Used only when command=create or command=modify. Valid values: true | false
- Specifies if this is a Multi-availability-zone deployment. Can not be used in conjunction with zone parameter. Used only when command=create or command=modify.
choices: [ "yes", "no" ]
required: false
required: false
default: null
default: null
aliases: []
aliases: []
@ -208,34 +212,34 @@ author: Bruce Pennypacker
EXAMPLES = '''
EXAMPLES = '''
# Basic mysql provisioning example
# Basic mysql provisioning example
action: rds
- rds: >
command=create
command=create
instance_name=new_database
instance_name=new_database
db_engine=MySQL
db_engine=MySQL
size=10
size=10
instance_type=db.m1.small
instance_type=db.m1.small
username=mysql_admin
username=mysql_admin
password=1nsecure
password=1nsecure
# Create a read-only replica and wait for it to become available
# Create a read-only replica and wait for it to become available
action: rds
- rds: >
command=replicate
command=replicate
instance_name=new_database_replica
instance_name=new_database_replica
source_instance=new_database
source_instance=new_database
wait=yes
wait=yes
wait_timeout=600
wait_timeout=600
# Delete an instance, but create a snapshot before doing so
# Delete an instance, but create a snapshot before doing so
action: rds
- rds: >
command=delete
command=delete
instance_name=new_database
instance_name=new_database
snapshot=new_database_snapshot
snapshot=new_database_snapshot
# Get facts about an instance
# Get facts about an instance
action: rds
- rds: >
command=facts
command=facts
instance_name=new_database
instance_name=new_database
register: new_database_facts
register: new_database_facts
'''
'''
@ -266,69 +270,69 @@ except ImportError:
def main():
def main():
module = AnsibleModule(
module = AnsibleModule(
argument_spec = dict(
argument_spec = dict(
command = dict(choices=['create', 'replicate', 'delete', 'facts', 'modify'], required=True),
command = dict(choices=['create', 'replicate', 'delete', 'facts', 'modify'], required=True),
instance_name = dict(required=True),
instance_name = dict(required=True),
source_instance = dict(required=False),
source_instance = dict(required=False),
db_engine = dict(choices=['MySQL', 'oracle-se1', 'oracle-se', 'oracle-ee', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web'], required=False),
db_engine = dict(choices=['MySQL', 'oracle-se1', 'oracle-se', 'oracle-ee', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web'], required=False),
size = dict(required=False),
size = dict(required=False),
instance_type = dict(aliases=['type'], choices=['db.t1.micro', 'db.m1.small', 'db.m1.medium', 'db.m1.large', 'db.m1.xlarge', 'db.m2.xlarge', 'db.m2.2xlarge', 'db.m2.4xlarge'], required=False),
instance_type = dict(aliases=['type'], choices=['db.t1.micro', 'db.m1.small', 'db.m1.medium', 'db.m1.large', 'db.m1.xlarge', 'db.m2.xlarge', 'db.m2.2xlarge', 'db.m2.4xlarge'], required=False),
username = dict(required=False),
username = dict(required=False),
password = dict(no_log=True, required=False),
password = dict(no_log=True, required=False),
db_name = dict(required=False),
db_name = dict(required=False),
engine_version = dict(required=False),
engine_version = dict(required=False),
parameter_group = dict(required=False),
parameter_group = dict(required=False),
license_model = dict(choices=['license-included', 'bring-your-own-license', 'general-public-license'], required=False),
license_model = dict(choices=['license-included', 'bring-your-own-license', 'general-public-license'], required=False),
multi_zone = dict(choices=BOOLEANS , default=False),
multi_zone = dict(type='bool' , default=False),
iops = dict(required=False),
iops = dict(required=False),
security_groups = dict(required=False),
security_groups = dict(required=False),
port = dict(required=False),
port = dict(required=False),
upgrade = dict(choices=BOOLEANS , default=False),
upgrade = dict(type='bool' , default=False),
option_group = dict(required=False),
option_group = dict(required=False),
maint_window = dict(required=False),
maint_window = dict(required=False),
backup_window = dict(required=False),
backup_window = dict(required=False),
backup_retention = dict(required=False),
backup_retention = dict(required=False),
ec2_region = dict(aliases=['EC2_REGION'], choices=AWS_REGIONS, required=False),
ec2_region = dict(aliases=['EC2_REGION'], choices=AWS_REGIONS, required=False),
zone = dict(required=False),
zone = dict(required=False),
subnet = dict(required=False),
subnet = dict(required=False),
ec2_secret_key = dict(aliases=['EC2_SECRET_KEY'], no_log=True, required=False),
ec2_secret_key = dict(aliases=['EC2_SECRET_KEY'], no_log=True, required=False),
ec2_access_key = dict(aliases=['EC2_ACCESS_KEY'], required=False),
ec2_access_key = dict(aliases=['EC2_ACCESS_KEY'], required=False),
wait = dict(choices=BOOLEANS , default=False),
wait = dict(type='bool' , default=False),
wait_timeout = dict(default=300),
wait_timeout = dict(default=300),
snapshot = dict(required=False),
snapshot = dict(required=False),
apply_immediately = dict(choices=BOOLEANS , default=False),
apply_immediately = dict(type='bool' , default=False),
)
)
)
)
command = module.params.get('command')
command = module.params.get('command')
instance_name = module.params.get('instance_name');
instance_name = module.params.get('instance_name');
source_instance = module.params.get('source_instance');
source_instance = module.params.get('source_instance');
db_engine = module.params.get('db_engine');
db_engine = module.params.get('db_engine');
size = module.params.get('size');
size = module.params.get('size');
instance_type = module.params.get('instance_type');
instance_type = module.params.get('instance_type');
username = module.params.get('username');
username = module.params.get('username');
password = module.params.get('password');
password = module.params.get('password');
db_name = module.params.get('db_name');
db_name = module.params.get('db_name');
engine_version = module.params.get('engine_version');
engine_version = module.params.get('engine_version');
parameter_group = module.params.get('parameter_group');
parameter_group = module.params.get('parameter_group');
license_model = module.params.get('license_model');
license_model = module.params.get('license_model');
multi_zone = module.params.get('multi_zone');
multi_zone = module.params.get('multi_zone');
iops = module.params.get('iops');
iops = module.params.get('iops');
security_groups = module.params.get('security_groups');
security_groups = module.params.get('security_groups');
port = module.params.get('port');
port = module.params.get('port');
upgrade = module.params.get('upgrade');
upgrade = module.params.get('upgrade');
option_group = module.params.get('option_group');
option_group = module.params.get('option_group');
maint_window = module.params.get('maint_window');
maint_window = module.params.get('maint_window');
subnet = module.params.get('subnet');
subnet = module.params.get('subnet');
backup_window = module.params.get('backup_window');
backup_window = module.params.get('backup_window');
backup_retention = module.params.get('module_retention');
backup_retention = module.params.get('module_retention');
ec2_region = module.params.get('ec2_region')
ec2_region = module.params.get('ec2_region')
zone = module.params.get('zone')
zone = module.params.get('zone')
ec2_secret_key = module.params.get('ec2_secret_key')
ec2_secret_key = module.params.get('ec2_secret_key')
ec2_access_key = module.params.get('ec2_access_key')
ec2_access_key = module.params.get('ec2_access_key')
wait = module.params.get('wait')
wait = module.params.get('wait')
wait_timeout = int(module.params.get('wait_timeout'))
wait_timeout = int(module.params.get('wait_timeout'))
snapshot = module.params.get('snapshot')
snapshot = module.params.get('snapshot')
apply_immediately = module.params.get('apply_immediately')
apply_immediately = module.params.get('apply_immediately')
# allow environment variables to be used if ansible vars aren't set
# allow environment variables to be used if ansible vars aren't set
if not ec2_secret_key and 'EC2_SECRET_KEY' in os.environ:
if not ec2_secret_key and 'EC2_SECRET_KEY' in os.environ:
@ -360,16 +364,20 @@ def main():
# Validate parameters for each command
# Validate parameters for each command
if command == 'create':
if command == 'create':
required_vars = [ 'instance_name', 'db_engine', 'size', 'instance_type', 'username', 'password' ]
required_vars = [ 'instance_name', 'db_engine', 'size', 'instance_type', 'username', 'password' ]
invalid_vars = [ 'source_instance', 'snapshot', 'apply_immediately' ]
invalid_vars = [ 'source_instance', 'snapshot', 'apply_immediately' ]
elif command == 'replicate':
elif command == 'replicate':
required_vars = [ 'instance_name', 'source_instance' ]
required_vars = [ 'instance_name', 'source_instance' ]
invalid_vars = [ 'db_engine', 'size', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'subnet', 'snapshot', 'apply_immediately' ]
invalid_vars = [ 'db_engine', 'size', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'subnet', 'snapshot', 'apply_immediately' ]
elif command == 'delete':
elif command == 'delete':
required_vars = [ 'instance_name' ]
required_vars = [ 'instance_name' ]
invalid_vars = [ 'db_engine', 'size', 'instance_type', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'port', 'upgrade', 'subnet', 'zone' , 'source_instance', 'apply_immediately' ]
invalid_vars = [ 'db_engine', 'size', 'instance_type', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'port', 'upgrade', 'subnet', 'zone' , 'source_instance', 'apply_immediately' ]
elif command == 'facts':
elif command == 'facts':
required_vars = [ 'instance_name' ]
required_vars = [ 'instance_name' ]
invalid_vars = [ 'db_engine', 'size', 'instance_type', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'port', 'upgrade', 'subnet', 'zone', 'wait', 'source_instance' 'apply_immediately' ]
invalid_vars = [ 'db_engine', 'size', 'instance_type', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'port', 'upgrade', 'subnet', 'zone', 'wait', 'source_instance' 'apply_immediately' ]
elif command == 'modify':
elif command == 'modify':
required_vars = [ 'instance_name' ]
required_vars = [ 'instance_name' ]
if password:
if password:
@ -378,11 +386,11 @@ def main():
for v in required_vars:
for v in required_vars:
if not module.params.get(v):
if not module.params.get(v):
module.fail_json(msg = str("Variable %s required for %s command" % (v, command)))
module.fail_json(msg = str("Parameter %s required for %s command" % (v, command)))
for v in invalid_vars:
for v in invalid_vars:
if module.params.get(v):
if module.params.get(v):
module.fail_json(msg = str("Variable %s invalid for %s command" % (v, command)))
module.fail_json(msg = str("Parameter %s invalid for %s command" % (v, command)))
# Package up the optional parameters
# Package up the optional parameters
params = {}
params = {}
@ -496,17 +504,17 @@ def main():
# If we got here then pack up all the instance details to send
# If we got here then pack up all the instance details to send
# back to ansible
# back to ansible
d = {
d = {
'id': my_inst.id,
'id' : my_inst.id,
'create_time': my_inst.create_time,
'create_time' : my_inst.create_time,
'status': my_inst.status,
'status' : my_inst.status,
'availability_zone': my_inst.availability_zone,
'availability_zone' : my_inst.availability_zone,
'backup_retention': my_inst.backup_retention_period,
'backup_retention' : my_inst.backup_retention_period,
'backup_window': my_inst.preferred_backup_window,
'backup_window' : my_inst.preferred_backup_window,
'maintenance_window': my_inst.preferred_maintenance_window,
'maintenance_window' : my_inst.preferred_maintenance_window,
'multi_zone': my_inst.multi_az,
'multi_zone' : my_inst.multi_az,
'instance_type': my_inst.instance_class,
'instance_type' : my_inst.instance_class,
'username': my_inst.master_username,
'username' : my_inst.master_username,
'iops': my_inst.iops
'iops' : my_inst.iops
}
}
# Endpoint exists only if the instance is available
# Endpoint exists only if the instance is available