删除一个S3目录通过Ansible播放本。

huangapple go评论72阅读模式
英文:

Delete an S3 directory via Ansible playbooks

问题

有办法使用Ansible playbooks递归删除所有内容的S3目录,或者我必须使用shell脚本吗?

目前的aws_s3s3_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

huangapple
  • 本文由 发表于 2023年4月17日 18:42:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034286.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定