Iâm trying the Ansible Tower Integration but i meet some problems, let me explain (i hope to explain this well, english is not my ânatural tongueâ ⌠)
I linked my Ansible Tower to ManageIQ in a heartbeat (thanks to this forum)
I created a button on the VM page that launch an Ansible Job on this VM (againâŚthx to this forum )
SoâŚnow i try to make a âworkflowâ :
Deploy a VM (on VMWare Provider) ===> run an Ansible job on this VM ==> âtadaaa pure magicâ
So for this I made a bundled catalog item : 1 item is the VM template deployement the 2nd is the Ansible Job without dialogs)
My ansible is very simple, just a POC (a touch on a file) with parameter âhost: allâ
When i run this playbook via my button, no problem, this run on the selected VM
When i run the bundled itemâŚthe vm deployement is OK but the playbook run on ALL the VM in inventoryâŚnot only on the VM which is deployedâŚ
SoâŚfirstâŚwhat i tryng to do is possible or iâm just fooling myself ?
What can be wrong ?
I tried to find a solution or some documentation all over the internet (i found a lot here ) but nothing on this kind of workflow (VM deployement + Ansible post configuration on the fly on the specific VM)
OkâŚso for the moment my POC for ManageIQ with Ansible Tower is a complete fail againsât Vrealize and System CenterâŚ
So i let ManageIQ until this system is âmatureâ and fully documented (where is the Ansible Tower integration Documentation ??? CâmonâŚthis is a major Feature and no Doc outhere ? Really ?)
@soissons I assume you have created a state machine that provisions the VM, waits for completion, then attempts to run the Ansible Tower Job Template. Is that correct?
Are you setting the limit properly when launching the Ansible Tower Job Template? If the limit is not set, I believe it will run on the whole inventory.
I run the bundled items, i put on Textbox my VM Name and the playbook run on the selected VM ( Victory ! ^^ but waitâŚhe run not properly, i will explain afterâŚ)
The Problem, now, is the Ansible Job start way before the completion of the VM deployementâŚso the Ansible Playbook run before the VM is up and readyâŚ
@soissons I donât think this can work as a bundle. The solution is to create a new automate state machine that does the VM provision first then does the Ansible Tower work once the VM is created, ensuring that the VM is available before the Job Template is triggered.
And if @jmarc is OK I will update this thread tomorrow with a step by step how to
PS: @bdunne In fact my previous workflow could work, not very efficient but he can work, just needed to add some previous step in SchemaâŚ(i will explain tomorrow)
No dialog and the Provisioning entry point is
/Service/Provisioning/StateMachine/ServiceProvision_Template/ Catalogiteminitialization.
(*jeremie is just my âcloned namespaceâ)
This item is a VM deployement from a template for VMware provider so configure it the proper way (if you are interested let me know i update the thread with some screenshot for that)
Second item is the Ansible job (when you create the Service catalog item, choose âAnsible towerâ type):
The dialog box that is important here is the âLimitâ one.
As i say previously this box will feed the limit parameter of Ansible to run on this specific host/VM.
Choose the dialog previously created and put the Provision entry point : /Service/Provisioning/StateMachines/ServiceProvision_Template/ CatalogbundleItemInitialization
Select you items and the sequencing (Ansible job in 2nd ):
The Ansible Job Template can only run once the VM is deployed and UP.
To ensure the ordering, add an initial âpre0â state with a value of /Service/Provisioning/StateMachines/Methods/GroupSequenceCheck to the state machine schema used to launch our AnsibleType service item ==>
@soissons cool article, I will take inspiration from this.
Btw. my problem was, that a provider can say the VM is ready, but you canât really ssh to it yet, cause itâs still doing some init. (happened with AWS). You can solve this nicely on the Tower side, when you start with a âwait for VM to be sshableâ, like this:
Hi. This thread has been helpful in getting a Tower Job template to run against a VM itâs bundled with, but I am having an issue that isnât covered hereâŚ
When I order my bundle. The service is created with the VM contained within, but another service is created with the same name and no VMs associated. This âghost serviceâ always errors when I try to retire it. It looks like itâs parented to the catalog item rather than the bundle. Parent should be âRHEL with Tower Jobâ
My Service bundle is set up almost exactly as it is in @soissons example. With a simple Ansible job with a debug message to just test the connection between Tower and the Management Engine. The one difference is that I define a service_name in addition to a vm_name in the service dialog.
Any idea how I can stop the Ansible-Tower Job Service Item from creating its own service or fix the parenting issue?
I solved the issue I was having with the method below.
begin
svc = $evm.root['service_template_provision_task'].destination
if svc.v_total_vms.zero?
svc.remove_from_vmdb
$evm.log(:info, 'Removed empty service from VMDB')
$evm.root['ae_next_state'] = 'Finished'
else
$evm.log(:info, 'Ansible job returned a VM')
# need to address parenting here
end
exit MIQ_OK
rescue => err
$evm.log(:error, "[#{err}]\n#{err.backtrace.join("\n")}")
exit MIQ_WARN
end
Added this to one of the post states of the state machine at: ConfigurationManagement/AnsibleTower/Service/Provisioning/StateMachines/Provision/provision_from_bundle
As you can see I still havenât solved the parenting issue if the Ansible job actually does return an inventory item. Thatâs a challenge for another day.
Great stuff. One thing I would like to add, if you donât want to kick off the Ansible Tower job at the same time as the VM build (in parallel), you can set the action order for both items in the bundle to 1. This will make them run serially.