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
- User requests VM from vRA Portal, specifying wich Playbook they want to run from a drop down list.
- vRA provisons RHEL/CENTOS 7 VM to vSphere
- 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.
- Ansible makes and SSH connection to the provisioned VM from the Ansible server and runs the specified playbook
- 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
- Install the private key from your template: More info how to do this here.
- 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)
- Add the range of ip addresses that you will be deploying hosts to in /etc/ansible/hosts for example 192.168.110[200:225]
- 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
- 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:
- Go to administration Tab
- Click on Property Definitions
- Click +New
Enter the following:
- Enter a name
- Enter the same for label
- Enter a discription
- Select String
- Select Yes
- Choose Dropdown
- Click New and create the selections
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 set you blocking task timeout and click next
- Check blocking
- Set the timeout for how long you want the vRO workflow to run before it gives up.
Pingback: vRA Ansible Integration 3 ways – VMtoCloud.com
Pingback: vRA with Ansible | Virtualisatieadvies