英文:
Delete an S3 directory via Ansible playbooks
问题
有办法使用Ansible playbooks递归删除所有内容的S3目录,或者我必须使用shell脚本吗?
目前的aws_s3
和s3_object
模块只能使用delobj
模式删除空目录。我正在寻找基于目录/键前缀的批量删除方法。
英文:
Is there a way to delete S3 directories recursively with all their content using Ansible playbooks or am I forced to use shell scripts?
Currently aws_s3
and s3_object
modules only offer deleting empty directories using delobj
mode. I'm looking for a bulk deletion based on directory/key prefix.
答案1
得分: 2
你将通过运行 aws --debug
实际观察到,即使使用 aws-cli,rm --recursive
的行为也是首先枚举键,然后逐个删除它们。因此,如果你想通过 ansible 进行操作,你需要使用 mode: list
加上 register:
来复制这个行为,并注意如果返回的键超过默认的 1000 个,可能需要使用 marker: 参数。
我听说的唯一替代方法是使用 S3 生命周期策略来删除对象,如果你有大量对象的话。
英文:
You'll actually observe by running aws --debug
that even with aws-cli the rm --recursive
behavior is to first enumerate the keys and then delete them one at a time. Thus, if you wanted to do it via ansible, you would need to replicate that behavior using mode: list
plus register:
and taking care if you have more than the 1000 default returned keys, likely via the marker:
parameter
The only alternative that I've ever heard is to use the S3 lifecycle policy to remove objects, if you have an incredible amount of them
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论