Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
Last active February 27, 2020 01:27
Show Gist options
  • Select an option

  • Save MatthewJDavis/c839c9619a0245f602b39ab7619ced2b to your computer and use it in GitHub Desktop.

Select an option

Save MatthewJDavis/c839c9619a0245f602b39ab7619ced2b to your computer and use it in GitHub Desktop.
Get dynamodb table names with Ansible
---
- 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