Google cloud platform 使用Ansible在Google云存储桶上启用对象生命周期管理
我正在尝试使用Ansible在GCP存储桶上启用版本控制和对象生命周期管理。为此,我创建了以下剧本Google cloud platform 使用Ansible在Google云存储桶上启用对象生命周期管理,google-cloud-platform,ansible,google-cloud-storage,Google Cloud Platform,Ansible,Google Cloud Storage,我正在尝试使用Ansible在GCP存储桶上启用版本控制和对象生命周期管理。为此,我创建了以下剧本 - name: create a bucket hosts: localhost tasks: - name: Storage bucket google.cloud.gcp_storage_bucket: name: ansible-storage-module project: adminproject-272208 auth_ki
- name: create a bucket
hosts: localhost
tasks:
- name: Storage bucket
google.cloud.gcp_storage_bucket:
name: ansible-storage-module
project: adminproject-272208
auth_kind: serviceaccount
service_account_file: "/home/project/ansible/project.json"
state: present
versioning:
enabled: true
lifecycle:
rule:
action:
type: Delete
condition:
ageDays: 3
isLive: false
但它失败了,错误如下
PLAY [create a bucket]
************************************************************************************************
TASK [Gathering Facts]
************************************************************************************************
ok: [localhost]
TASK [Storage bucket]
*************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "argument rule is of type <type 'dict'> found in 'lifecycle'. and we were unable to convert to list: <type 'dict'> cannot be converted to a list"}
PLAY RECAP
********************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
但是,在检查时,无法看到版本控制和生命周期规则都未实现
$ gsutil versioning get gs://ansible-storage-module/
gs://ansible-storage-module: Suspended
$ gsutil lifecycle get gs://ansible-storage-module/
gs://ansible-storage-module/ has no lifecycle configuration.
从中可以看出,
lifecycle.rule
参数应该是一个dict列表,而不是dict本身。使用相同的规则创建了一个新的bucket,它就工作了。同时创建版本控制和生命周期规则。因此,似乎不适用于现有桶
$ gsutil versioning get gs://ansible-storage-module/
gs://ansible-storage-module: Suspended
$ gsutil lifecycle get gs://ansible-storage-module/
gs://ansible-storage-module/ has no lifecycle configuration.