1 minute read

February 2020

Overview

I was working on an Ansible playbook to remove a DynamoDB table for a tear down job for features based on their tag values using the Ansible DynamoDB module which was going well until it came to features using multiple tables. For the module to work, you need to supply the table’s name and there is no native Ansible module that allows you to get the name of the DynamoDB tables in the AWS accounts. A way to get around this and what I show below is to use the AWS Cli and Ansible command module.

Below is the script I used to achieve this, including how to create a new list of just the table names that I read about on Jeff Geerling’s blog.

Playbook

Console with 4 DynamoDB tables

Console showing tables

Running the script above, returns 3 of the tables that match the tag values provided

Output of playbook to get table names

To remove the tables

I add the code below to the script. This use the DynamoDB table module to remove all the tables in the list I had created by looping over that list and passing the module each table name to remove.

Output of deleting tables playbook run

Output of removed playbook run

Console has been updated

Removed tables from the console

Summary

Although you currently you can’t use the dynamodb_table module to get a list of tables, using the command module, AWS CLI and the Ansible split function to get the table name is a good solution to get DynamoDB table names by given tag values. This can be used in the automation of Dynamodb tables such as deleting them or modifying them using Ansible playbooks.