vRA with Ansible Server and vRO integration

In this guide I will show you to use a Software Components Blueprint to integrate Ansible Playbooks. In this example I am using what I describe as Ansible Enterprise. Meaning, there is no Ansible binary installed on the provisoned VM’s and there is no internet access required from the provisoned VM’s. I have also copied my Git repository with the example playbooks to the Ansible Server. See a demo video of this solution https://www.youtube.com/watch?v=3SD7RhYzZ4k

Pre-Reqs

  • Working installation of vRealize Automation 7
  • Cloud Client 4 installed download here
  • Download the Ansible vRO workflow here
  • Download the Ansible_Examples_Server blueprint here
  • Working vRealize RHEL/CENTOS 7 Blueprint – See my guide here
  • SE Linux enabled in Passive Mode in the above template see here for instructions
  • SSH key based login from the Ansible server to this template see here
  • Ansible Server with git installed you can download my blueprint here
  • Access to the Ansible server from the provisioned VM

Credits:

I want to thank Gary Coburn @coburngary for his help and blog resource at http://extendingclouds.com/enabling-the-event-broker/

Overview of the flow of this integration

  1. User requests VM from vRA Portal, specifying wich Playbook they want to run from a drop down list.
  2. vRA provisons RHEL/CENTOS 7 VM to vSphere
  3. Once VM is up and running we run an orchestrator workflow that will SSH into the Ansible Server to pass the IP address and the selected playbook and run Ansible.
  4. Ansible makes and SSH connection to the provisioned VM from the Ansible server and runs the specified playbook
  5. Once complete, the requester gets notification that their VM is provisioned and they can see that their selected playbook was run.

Setting up the Ansible Server

  1. Install the private key from your template: More info how to do this here.
  2. Modify the ~/.ssh/known_hosts file to add the ip range you will be deploying VM’s to. (In my environment I am using root login for everything)
  3. Add the range of ip addresses that you will be deploying hosts to in /etc/ansible/hosts for example 192.168.110[200:225]
  4. change to the tmp directory and clone the git repo at https://github.com/vmtocloud/ansible-examples git clone https://github.com/vmtocloud/ansible-examples.git
  5. Create a shell file named runplaybook.sh in /tmp/ with the following content
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/root/bin
export host=$1
export playbook=$2
cd /tmp
cd ansible-examples/$playbook
ansible-playbook site.yml -l $host

Import the Ansible_Examples_Server blueprint using cloud client

See my guide here

Create your Playbooks_EL7 drop down list:

  1. Go to administration Tab
  2. Click on Property Definitions
  3. Click +New
    Property Definition

Enter the following:

  1. Enter a name
  2. Enter the same for label
  3. Enter a discription
  4. Select String
  5. Select Yes
  6. Choose Dropdown
  7. Click New and create the selections

Make sure to update the blueprint with your template settings

Import the provided vRO workflow to your vRO instance

Edit the workflow and set the attributes for your Ansible server and the user and password you will SSH to it with

Now create a Event Subscription to call the vRO workflow when the machine is provisioned

Click Administration, Events, Subscriptions, then click New

Select Machine Provisioning and click next

Now select Run based on conditions, all of the following and dig down to Lifecycle state name

Select Equals and dig down to VMPSMasterWorkflow32MachineActivated

No add another condition and dig down to State Phase

Select Equals and choose POST then click next in the bottom right

Now browse and select the workflow we uploaded to vRO earlier

Now set you blocking task timeout and click next

  1. Check blocking
  2. Set the timeout for how long you want the vRO workflow to run before it gives up.

Entile your bluprint and fire off a new request

Remember sharing is caring!

2 Replies to “vRA with Ansible Server and vRO integration”

  1. Pingback: vRA Ansible Integration 3 ways – VMtoCloud.com

  2. Pingback: vRA with Ansible | Virtualisatieadvies