Bootstrap FreeKB - Ansible - List Amazon Web Services (AWS) S3 Buckets using the aws_s3_bucket_info module
Ansible - List Amazon Web Services (AWS) S3 Buckets using the aws_s3_bucket_info module

Updated:   |  Ansible articles

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

Prerequisites

aws_s3_bucket_info can be used to list your Amazon Web Services (AWS) S3 Buckets. 

---
- name: main play
  hosts: localhost
  tasks:
  - name: list S3 Buckets
    community.aws.aws_s3_bucket_info:
    register: out

  - debug:
      var: out
...

 

Something like this should be returned.

ok: [localhost] => (item={u'name': u'my-bucket-abcdefg', u'creation_date': u'2023-06-02T02:22:19+00:00'}) => {
    "ansible_loop_var": "item",
    "item": {
        "creation_date": "2023-06-02T02:22:19+00:00",
        "name": "my-bucket-abcdefg"
    },
    "item.name": "my-bucket-abcdefg"
}

 

Extra parameters such as the buckets Tags can be returned like this.

---
- name: main play
  hosts: localhost
  tasks:
  - name: list S3 Buckets
    community.aws.aws_s3_bucket_info:
      bucket_facts:
        bucket_tagging: true
    register: out

  - debug:
      var: out
...

 

Which should return something like this.

ok: [staging_docker_2] => {
    "s3_buckets": {
        "buckets": [
            {
                "bucket_tagging": {
                    "environment": "staging"
                },
                "creation_date": "2023-07-21T23:17:02+00:00",
                "name": "my-bucket-abcdefg"
            }
        ],
        "changed": false,
        "failed": false,
        "msg": "Retrieved s3 info."
    }
}

 

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 10ce48 in the box below so that we can be sure you are a human.