community.general.gc_storage (1.3.14) — module

This module manages objects/buckets in Google Cloud Storage.

Authors: Benno Joy (@bennojoy), Lukas Beumer (@Nitaco)

Install collection

Install with ansible-galaxy collection install community.general:==1.3.14


Add to requirements.yml

  collections:
    - name: community.general
      version: 1.3.14

Description

This module allows users to manage their objects/buckets in Google Cloud Storage. It allows upload and download operations and can set some canned permissions. It also allows retrieval of URLs for objects for use in playbooks, and retrieval of string contents of objects. This module requires setting the default project in GCS prior to playbook usage. See U(https://developers.google.com/storage/docs/reference/v1/apiversion1) for information about setting the default project.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Upload some content
  community.general.gc_storage:
    bucket: mybucket
    object: key.txt
    src: /usr/local/myfile.txt
    mode: put
    permission: public-read
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Upload some headers
  community.general.gc_storage:
    bucket: mybucket
    object: key.txt
    src: /usr/local/myfile.txt
    headers: '{"Content-Encoding": "gzip"}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Download some content
  community.general.gc_storage:
    bucket: mybucket
    object: key.txt
    dest: /usr/local/myfile.txt
    mode: get
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Download an object as a string to use else where in your playbook
  community.general.gc_storage:
    bucket: mybucket
    object: key.txt
    mode: get_str
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create an empty bucket
  community.general.gc_storage:
    bucket: mybucket
    mode: create
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a bucket with key as directory
  community.general.gc_storage:
    bucket: mybucket
    object: /my/directory/path
    mode: create
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete a bucket and all contents
  community.general.gc_storage:
    bucket: mybucket
    mode: delete
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a bucket with versioning enabled
  community.general.gc_storage:
    bucket: "mybucket"
    versioning: yes
    mode: create
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a bucket located in the eu
  community.general.gc_storage:
    bucket: "mybucket"
    region: "europe-west3"
    mode: create

Inputs

    
src:
    description:
    - The source file path when performing a PUT operation.
    type: str

dest:
    description:
    - The destination file path when downloading an object/key with a GET operation.
    type: path

mode:
    choices:
    - get
    - put
    - get_url
    - get_str
    - delete
    - create
    description:
    - Switches the module behaviour between upload, download, get_url (return download
      url) , get_str (download object as string), create (bucket) and delete (bucket).
    required: true
    type: str

bucket:
    description:
    - Bucket name.
    required: true
    type: str

object:
    description:
    - Keyname of the object inside the bucket. Can be also be used to create "virtual
      directories" (see examples).
    type: path

region:
    default: US
    description:
    - The gs region to use. If not defined then the value 'US' will be used. See U(https://cloud.google.com/storage/docs/bucket-locations)
    type: str

headers:
    default: {}
    description:
    - Headers to attach to object.
    type: dict

overwrite:
    aliases:
    - force
    default: 'yes'
    description:
    - Forces an overwrite either locally on the filesystem or remotely with the object/key.
      Used with PUT and GET operations.
    type: bool

expiration:
    aliases:
    - expiry
    default: 600
    description:
    - Time limit (in seconds) for the URL generated and returned by GCA when performing
      a mode=put or mode=get_url operation. This url is only available when public-read
      is the acl for the object.
    type: int

permission:
    choices:
    - private
    - public-read
    - authenticated-read
    default: private
    description:
    - This option let's the user set the canned permissions on the object/bucket that
      are created. The permissions that can be set are 'private', 'public-read', 'authenticated-read'.
    type: str

versioning:
    default: false
    description:
    - Whether versioning is enabled or disabled (note that once versioning is enabled,
      it can only be suspended)
    type: bool

gs_access_key:
    description:
    - GS access key. If not set then the value of the GS_ACCESS_KEY_ID environment variable
      is used.
    required: true
    type: str

gs_secret_key:
    description:
    - GS secret key. If not set then the value of the GS_SECRET_ACCESS_KEY environment
      variable is used.
    required: true
    type: str