def main()

in src/ansible_collections/alibaba/apsarastack/plugins/modules/ali_rds_instance_info.py [0:0]


def main():
    argument_spec = common_argument_spec()
    argument_spec.update(dict(
        name_prefix=dict(type='str'),
        db_instance_ids=dict(type='list', elements='str'),
        tags=dict(type='dict')
    ))
    module = AnsibleModule(argument_spec=argument_spec)
    rds = rds_connect(module)
    name_prefix = module.params['name_prefix']
    db_instance_ids = module.params['db_instance_ids']

    if HAS_FOOTMARK is False:
        module.fail_json(msg="Package 'footmark' required for this module.")

    result = []
    try:
        for rds_instance in rds.describe_db_instances(**module.params):
            if name_prefix and not rds_instance.read()['name'].startswith(name_prefix):
                continue
            if db_instance_ids and rds_instance.read()['id'] not in db_instance_ids:
                continue
            result.append(rds_instance.get().read())
        module.exit_json(changed=False, instances=result)
    except Exception as e:
        module.fail_json(msg="Unable to describe rds db instance, and got an error: {0}.".format(e))