Ansible and Astra DB APIs — A Match Made in Heaven

Ansible is a predictive, simple, and reliable tool that has an agentless architecture that delivers simple IT automation that ends (once for all!) repetitive tasks and frees up DevOps teams for more strategic work. It dramatically reduces the burden in managing the lifecycle of your infrastructure by automating the repetitive work which is the drudgery of IT admins in their day-to-day tasks and boosts productivity. As Ansible documentation tells us, “Complexity kills productivity!”.

Every business is a digital business today. Technology is your innovation engine, and delivering your applications faster helps you win. Historically, that required a lot of manual effort and complicated coordination. But today, there is Ansible, the simple, yet powerful IT automation engine that thousands of companies are using to drive complexity out of their environments and accelerate DevOps initiatives.

DataStax Astra DB offers a rich set of APIs. The DevOps API makes it easy to script the creation and management of an Astra DB database, roles, security tokens, access lists, and private links for your database. And, with Stargate, Astra users have easy access to built-in APIs (REST, gRPC, GraphQL, and Document) to work with the data.

You may have queried APIs with a Postman, a web browser, or cURL, but one of the overlooked capabilities of Ansible is how well it can leverage APIs as part of the playbook. This is extremely useful because the number of APIs being built and offered both by Astra and across the global internet-scale companies is exponentially increasing day by day. There’s even a public-apis GitHub repo listing hundreds of free APIs over a dozen categories.

In this post, we are going to walk you through how to use Ansible to leverage Astra DB’s DevOps APIs and Stargate Data APIs. In this repo, we give you the Ansible playbook to interact with Astra APIs for getting the database up and running with the required table(s) for your application(s) to begin kicking the tires.

Let’s get started!

With just one single playbook, we will be demonstrating the operations needed to begin leveraging your database. These steps will help you get your Astra DB up and running and the tables ready to go for your applications:

  1. Create a token to use the Astra DevOps API endpoints (this is only supported for classic tier Astra DBs).
  2. Return supported regions and availability for a given user and org combination.
  3. Create a new Astra database and create a keyspace on the created DB.
  4. Find the created Astra database using its ID.
  5. Obtain the secure connect bundle for the created Astra database using its ID.
  6. Create a token to use the Data API for the Astra database using its ID.
  7. Return all keyspaces in the Astra database using its ID.
  8. Add a table in the created Astra database.
  9. Return all tables in the Astra database using its ID.
  10. Resize the already created Astra database (this is only supported for non-free tier classic tier Astra DBs).
  11. Park the already created Astra database (this is only supported for classic tier Astra DBs).
  12. Unpark the already parked Astra database (this is only supported for classic tier Astra DBs).

Getting set up with the necessary prerequisites

  1. Download and set Ansible up on the control machine from where you’ll be executing the Ansible playbook. In this example, we used version 2.9.13.
  2. Sign into DataStax Astra DB portal and create an Application Token. We are going to use the API Admin Svc Account role here to generate the token. Save the generated token details by downloading the CSV. Tip: This step can also be created using the DevOps API, but we wanted to show you the Astra DB portal mechanism as well here!
  3. Download the astra_api.yml file to your Ansible control machine. If you’re curious, you could dive into this playbook to understand the operations. All that’s needed is Ansible’s core uri module to achieve what we want.

Executing the Ansible playbook

Run the astra_api.yml Ansible playbook using the below command on the Ansible control machine. You’ll experience all the actions/tasks being executed sequentially as defined in the playbook.

You’ll be asked to provide answers/values for the questions one after the other which are required to execute the playbook. Just hit enter for the optional ones. See the below table for additional details.

Alternatively, one could pass in the answers/values via command-line arguments by running the following:

Let’s see what’s all these Ansible playbook input variables mean to us:

And, voila!! ✨ We’ve successfully performed a series of operations leveraging Astra DevOps API and the built-in Stargate APIs to spin up a free-tier database.

Below, you’ll see an example of what the last line of the output will look like once your playbook has been completed successfully. There’s also a longer example of the output at the end of this post, which we’ve shortened for the sake of brevity. Note that the playbook would have skipped agenda items 1, 10, 11, and 12 here during this run, as this operation is not required with serverless tier Astra DBs, but we wanted to showcase what’s possible for classic tier Astra DBs.

This is the last line of the playbook’s run output:

Upon the run completion, you’ll see the following in the Astra DB portal:

Figure 1. DataStax Astra portal showing the created free-tier database.

And, when you click on the “CQL Console” menu/section to explore the created data model schema by describing it, you’ll notice output similar to below:

Figure 2. DataStax Astra portal showing the created free-tier database’s data model/schema.

And, here’s a simplified example of the run output:

We’ve only scratched the surface in this post in terms of what’s possible. Now that you’ve seen the power of leveraging Ansible with Astra APIs, if you’re a Terraform enthusiast, we’ve got you covered there, too.

With the ever-increasing capabilities of the Astra DevOps API and Stargate data APIs built into Astra, there’s a lot more that you can do with it, including creating the users, their tokens, access list, private link, and more! If you’re not already using Astra DB, maybe it’s time to take it for a spin. You can sign up for free here!

Follow the DataStax Tech Blog for more developer stories. Check out our YouTube channel for tutorials and here for DataStax Developers on Twitter for the latest news about our developer community.

Resources

  1. Ansible
  2. DataStax Astra DB
  3. Classic tier Astra DB (Astra Documentation)
  4. Serverless tier Astra DB (Astra Documentation)
  5. DevOps API for managing your databases (Documentation)
  6. Stargate
  7. Get a Head Start on Your App Development with Flexible DataStax Stargate APIs
  8. Qualify Your Database Needs with DataStax Astra Stargate REST API
  9. Say Goodbye to Native Drivers with Stargate gRPC API in Java
  10. How to get just the data you need with the Stargate GraphQL API in a simple coding scenario
  11. Create and Use a Document Database with Stargate Document API and Astra DB in 15 Minutes
  12. GitHub public repo with a collective list of free APIs
  13. Installation Guide for Installing Ansible
  14. Manage application tokens (Astra Documentation)
  15. User Permissions (Astra Documentation)
  16. Astra API .yml file on GitHub
  17. Ansible core uri module
  18. Ansible control machine
  19. Astra DB Glossary (Astra Documentation)
  20. Security Highlights (Astra Documentation)
  21. Using the Astra DB DevOps & Data APIs Reference
  22. Using the Astra DB DevOps APIs examples (Astra Documentation)
  23. Automate Database Infrastructure with Astra DB Terraform Provider

--

--

--

We’re huge believers in modern, cloud native technologies like Kubernetes; we are making Cassandra ready for millions of developers through simple APIs; and we are committed to delivering the industry’s first and only open, multi-cloud serverless database: DataStax Astra DB.

Recommended from Medium

How To Deploy Your .NET Core App on an IIS Server

Issues with scaling Pollpass

Design Your AML Program

Flutter Container Usage

Puzzle #28: can you find the number?

Remix in VSCode: Compiling, debugging, Metamask & Remixd

Async programming in R and Shiny

The error tracking space is heating up

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
DataStax

DataStax

DataStax is the company behind the massively scalable, highly available, cloud-native NoSQL data platform built on Apache Cassandra®.

More from Medium

Python Web App — Kubernetes Deployment with Helm Chart

Cassandra Monitoring Setup Using Open Source Tools

How to Analyze Prometheus Alertmanager Alerts Using S3, Athena and CloudFormation

KubeOrbit was released, solving problems in integration testing