def main(): argument_spec = oss_bucket_argument_spec() argument_spec.update( dict(bucket=dict(aliases=["name"]), bucket_prefix=dict(type="str"))) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json(msg="Package 'footmark' required for this module.") try: oss_service = oss_service_connect(module) keys = oss_service.list_buckets(prefix=module.params['bucket_prefix'], max_keys=200) buckets = [] bucket_names = [] for name in keys: module.params['bucket'] = name bucket = oss_bucket_connect(module) buckets.append(get_info(bucket)) bucket_names.append(bucket.name) module.exit_json(changed=False, bucket_names=bucket_names, buckets=buckets, total=len(buckets)) except Exception as e: module.fail_json( msg="Unable to describe buckets, and got an error: {0}.".format(e))
def main(): argument_spec = oss_bucket_argument_spec() argument_spec.update( dict( state=dict(required=True, choices=['present', 'absent', 'list']), permission=dict( default='private', choices=['private', 'public-read', 'public-read-write'], aliases=['acl']), bucket=dict(required=True, aliases=["name"]), )) module = AnsibleModule(argument_spec=argument_spec) if HAS_FOOTMARK is False: module.fail_json( msg="Package 'footmark' required for the module alicloud_bucket.") oss_bucket = oss_bucket_connect(module) state = module.params['state'] permission = module.params['permission'] if state == 'present': try: if oss_bucket.is_exist(): result = oss_bucket.put_acl(permission=permission) else: result = oss_bucket.create(permission=permission) module.exit_json(changed=True, bucket=get_bucket(result)) except Exception as e: module.fail_json( msg= "Unable to put bucket or set acl for it, and got an error: {0}." .format(e)) elif state == 'absent': try: oss_bucket.delete() module.exit_json(changed=True) except Exception as e: module.fail_json( msg="Unable to delete bucket, and got an error: {0}.".format( e)) else: try: oss_service = oss_service_connect(module) keys = oss_service.list_buckets(prefix=module.params['bucket'], max_keys=200) buckets = [] for name in keys: module.params['bucket'] = name buckets.append(get_bucket(oss_bucket_connect(module))) module.exit_json(changed=False, buckets=buckets) except Exception as e: module.fail_json( msg="Unable to list buckets, and got an error: {0}.".format(e))