Using Ansible to enable object lifecycle managent on Google Cloud Storage buckets

Viewed 178

I am trying to enable versioning and Object lifecycle management on a GCP storage bucket using Ansible. For this I created the following playbook

- 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

But it is failing with below error

   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

Any suggestion to resolve this ?

UPDATES

Modified as below the lifecycle part and it seems to PASS with no error

  lifecycle:
    rule:
       - action:
           type: Delete
         condition:
          is_live: no
          age_days: 3
       - action:
            type: Delete
         condition:
            is_live: no
            num_newer_versions: 3

PLAY RECAP   *******************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

However on checking cannot see neither versioning nor lifecycle rules are implemented

    $ 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.
0 Answers
Related