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
In your blueprint , select a vSphere machine and click on Properties (1), Custom Properties (2) and click on New (3)
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.
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
Edit your Ansible Tower Inventory profile and scroll to your Groups section
Type in the value you created on your blueprints. In this example, it will be {{ServerType}} then click the green plus
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.
Create a New Ansible Tower Profile by selecting Request on Add Ansible Tower Profile in your Catalog
In the Job Templates List. Setup the order of the jobs to run. In this example. I Will be setting tier3, tier2 than tier1
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.
Access your blueprint and then click on the gear icon next to your blueprint name at the top of your blueprint
Click on Properties (1), Property Groups (2) and then click on Add (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
Click On Finish
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
Related articles
SovLabs Ansible Tower Module : http://docs.sovlabs.com/latest/vmware-vra7x-plugin/modules/configuration-mgmt/ansible-tower/
0 Comments