Squashing tool sprawl is one of the strengths of RackN Digital Rebar Infrastructure Pipelines. You’re probably already using things like Terraform and Ansible to automate building cloud infrastructures. I’m sure you aren’t looking to start over again with yet another tool. We agree – you shouldn’t have to!

Infrastructure Pipelines help you use your existing tools to normalize operations. For instance, maybe you have Ansible stand-alone playbooks that you’ve customized for every machine you bring up. Wouldn’t it be great if you could inject those playbooks right into the machine’s build process? 

In this blog post, we’ll show you how to use Ansible stand-alone playbooks with Digital Rebar Infrastructure Pipelines.  Ansible is a very expressive and helpful DSL for configuration. However, building and maintaining an inventory file to perform small sets of Ansible tasks can be a lot of overhead.  

This post will focus on injecting your custom Ansible stand-alone playbooks into the Digital Rebar cluster provisioning pipeline process. If you’ve never worked with Digital Rebar before, you may want to review this blog post. And if you’d like to follow along with this post, make sure you’ve started a trial!

Setting up a default cluster

We’re starting with a default cluster we built with the default Digital Rebar cluster pipeline. Did you know Rackn’s default cluster pipeline builds groups of cloud instances via modular Terraform? But that’s for a future post. 

When we build the single-machine cluster has been built, we chose where to build the machines using the broker/set-pipeline parameter. Next, the generic cluster provision process (universal-application-application base) runs.

Create the Cluster with Pipeline

What happens in the background?  First, Terraform runs the request to build the cluster and applies the pipeline. Once the machine is created it checks in with Digital Rebar, and starts the pipeline. This pipeline automatically switches to the universal runbook. Finally, the universal runbook performs tasks like updating Linux packages. 

Cluster Pipeline calls Terraform via Broker

Now we have a cluster pipeline, complete with instructions on creating machines! However, this pipeline is very generic. We still need a way to get our site-specific Ansible ad hoc playbooks into the pipeline. Wouldn’t it be nice if Ansible automatically applied the site-specific instructions every time a server is created? This is how we add it to the Digital Rebar cluster pipeline.

Injecting Ansible ad hoc playbooks into an Infrastructure Pipeline

These are the steps you’ll need to follow to make sure your ad hoc playbooks are applied every time a new machine is created with this pipeline. You can also follow along in the video below.

Step 1: Customize the cluster pipeline.

Clone the universal-application-application-base profile

Application Base Chain Map
Step 1: Clone Application Base

Step 2: Change the default cluster pipeline Operational Params names.

Update the name of the profile and the universal/application param.  

Creating A Cluster

Step 3: Add Ansible to your pipeline.

Define one flexiflow Param to add an Ansible run to a pipeline.  

Step 3: Define Flexiflow Param

Time to inject some Ansible into this pipeline! The runbook map has pre-defined flexiflow injection points (-pre, -during, -post). For this pipeline, adding Ansible ad hoc playbooks is the core pipeline, we’ll add the code to the -during injection point.
Leveraging the existing runbook map for injecting work into a pipeline means you don’t have to change the chain map at all.

Step 4: Tell the universal runbook when to run Ansible.

Define a parameter that tells flexiflow to run Ansible ansible-playbooks-local during the universal-runbook workflow.

Step 5: Inject Ansible Task


The Digital Rebar task library has several generic Ansible run tasks that can help get you started.

Step 5: Define the Ansible Playbook location.

This can be a user-defined Digital Reber template, HTTP site, or a git repo.

Just want to try out the Ansible injection? The default Digital Rebar provides a test playbook, so you can skip defining one. The Ansible task will do all the work, even install Ansible if needed!

Step 6: Define Playbook

Step 6: Use your new pipeline!

The next time you create the cluster, check out the activity tab or job logs to see the playbook results.

Pipeline Running Ansible Playbook

This video shows how to put it all together:

I have an Infrastructure Pipeline with my Ansible scripts – now what?

The Universal Application can be used to create a cluster by referencing the new pipeline in broker/set-pipeline. That way, new machines will automatically run your Ansible playbook after they are created. 

The beautiful thing about this is now that you’ve done the work, you can change your broker and use this Infrastructure Pipeline on another cloud, or even in your datacenter!

But wait, there’s more! All of the components described are easily converted to immutable Infrastructure as Code by including them into Digital Rebar content packages.

Real Talk

Reusing work you’ve already done, such as Ansible ad hoc scripts to build machines, is one of the benefits of Digital Rebar. Infrastructure as Code shouldn’t start from scratch! You know how your machines need to be built, and you probably have already invested lots of time and work to build components. Ultimately, you need a platform like Digital Rebar to help you bring it all together.

Try Infrastructure Pipelines with your custom Ansible playbooks using our free trial. Make sure to keep an eye out for our post on using RackN Digital Rebar with Terraform.