How To - Multi tier Blueprint with Ansible Tower module

This article will provide you with guidance on how to configure a multi tier blueprint in vRA with Ansible Tower profiles attached at each tier. We will also provide some information on the Ansible Tower configuration and groups so that playbooks are executed in a specific order on the blueprint completion for each tier of your blueprint.

If you have vRA Enterprise you could utilise our Ansible Tower CM Framework plugin to achieve something similar. However, if you prefer or only have vRA Advanced then this guide is for you.

Instructions

In this example we will setup a 3 tier blueprint including dependencies with the following:

  • A custom property on each tier that describes the tier ie; tier1, tier2 or tier3

  • Add the custom property name as a group to your Ansible Tower inventory profile

  • Single Ansible Tower profile containing all the Ansible Tower playbooks you want to run

  • Set the hosts in your Ansible Tower playbooks to the value of your custom property value

Add a custom property to your blueprints

  1. In your blueprint , select a vSphere machine and click on Properties (1), Custom Properties (2) and click on New (3)

  2. In the name field, provide a name for your custom property. In this instance we will give a name of ServerType. In the Value field, provide something meaningful for this. In this example I will use tierN (Where N is 1, 2 or 3). and click OK.

  3. Repeat steps 1 and 2 for the other vSphere machines on your blueprint with the appropriate values.

Update your Ansible Tower Inventory Profile and add a new Group

In this section we will update the Inventory profile and add a new group to the groups section. This group will be the custom property you added to each tier in your blueprint

  1. Edit your Ansible Tower Inventory profile and scroll to your Groups section

  2. Type in the value you created on your blueprints. In this example, it will be {{ServerType}} then click the green plus

  3. Click on Submit

Update your Ansible Tower Playbooks in Ansible

We won’t run through how to update your playbooks in this section. But what you will need to do to ensure the groups you created work as expected is to make sure you update the Hosts: section of your playbooks to reflect the group you added to the Inventory Profile.

Example:

In the playbook you would have used to configure your tier1 servers, you may have your hosts look like the following:

- hosts: all

Now you would want this to run specifically against your group of servers that have the Name:value of:
ServerType : tier1

- hosts: tier1

So your playbook may resemble something like the following (This is a simple playbook as an example)

- hosts: tier1
  remote_user: root
  connection: ssh
  gather_facts: yes
  vars:
    username: myusername
  tasks:
  - name: Install the latest Apache Version
    yum: 
      name: httpd
      state: latest
    notify:
    - startservice
  handlers:
  - name: startservice
    service:
      name: httpd
      state: restarted

Do this for each tiers playbooks you need to run.

Create an Ansible Tower Profile containing all of your playbooks

When you create your new profile, you want to add each of the playbooks that relates to your tiers in the specific order of your dependencies. For example. If you need to configure your database server first, then your application server and then your webservers. You would add the playbook/s for your database servers first, then the playbooks for your application servers second and lastly your web server playbooks.

We will assume you have create Ansible profiles before so we won’t go over every step.

  1. Create a New Ansible Tower Profile by selecting Request on Add Ansible Tower Profile in your Catalog

  2. In the Job Templates List. Setup the order of the jobs to run. In this example. I Will be setting tier3, tier2 than tier1

  3. If you need deprovision templates then please add them here with the remaining information and submit.

Add your Ansible Tower Profile to your vRA blueprint

Traditionally, you would be adding your Ansible Tower profile to each vSphere Machine on your blueprint. Because we want to deploy 3 tiers and we have the Ansible Tower profile trigger on blueprint completion, we want to run this against the top level of the blueprint.

  1. Access your blueprint and then click on the gear icon next to your blueprint name at the top of your blueprint

  2. Click on Properties (1), Property Groups (2) and then click on Add (3)


  3. Place a check next to the Ansible Tower profile for your 3 tier blueprint and click on OK and then Click OK to get back to your Blueprint

  4. Click On Finish

  5. You are now ready to deploy your blueprint and validate that the deploy runs in the dependency order and also that the Ansible Tower playbooks run in your specific order.

The Result

When your playbooks run they will run in the order you specified and against the custom property on your blueprint.

So in my example, there are 5 servers in total. 2 of which are web server, 1 app and 1 db. So in Tier 3 I have my DB server and I can see the limit sees all the servers in my blueprint.

But in the task being run, it shows only 1 (one) server the playbook running against.

The same goes for my Web Server (tier1) it has deployed against only the 2 servers

And to prove this out, it ran the Ansible Tower Playbooks in the order we specific in our Ansible Tower Profile

SovLabs Ansible Tower Module : http://docs.sovlabs.com/latest/vmware-vra7x-plugin/modules/configuration-mgmt/ansible-tower/

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.