Last active
February 27, 2020 01:27
-
-
Save MatthewJDavis/c839c9619a0245f602b39ab7619ced2b to your computer and use it in GitHub Desktop.
Get dynamodb table names with Ansible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - hosts: localhost | |
| connection: local | |
| gather_facts: no | |
| vars: | |
| dynamodb_table_names: [] | |
| feature: "matttestdb" | |
| environment: "qa" | |
| tasks: | |
| - name: Set AWS region | |
| command: > | |
| aws configure set region "{{ region }}" | |
| - name: Get dynamodb | |
| command: > | |
| aws resourcegroupstaggingapi get-resources \ | |
| --tag-filters Key=feature,Values="{{ feature }}" Key=env,Values="{{ environment }}" --resource-type-filters 'dynamodb' | |
| register: table_list | |
| - name: table_info | |
| set_fact: | |
| info: "{{ table_list.stdout }}" | |
| register: table_info | |
| - name: Build a list of all the dynamodb table names. | |
| set_fact: | |
| dynamodb_table_names: "{{ dynamodb_table_names }} + [ '{{ item.ResourceARN.split('/')[1] }}' ]" | |
| with_items: " {{ table_info.ansible_facts.info.ResourceTagMappingList }}" | |
| - name: Output the dynamodb table names | |
| debug: | |
| var: dynamodb_table_names | |
| Resources used | |
| # https://www.jeffgeerling.com/blog/2017/adding-strings-array-ansible | |
| # https://docs.ansible.com/ansible/latest/modules/dynamodb_table_module.html#dynamodb-table-module | |
| # https://docs.aws.amazon.com/cli/latest/reference/resourcegroupstaggingapi/get-resources.html | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment