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)
@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.
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.
svc = $evm.root['service_template_provision_task'].destination
$evm.log(:info, 'Removed empty service from VMDB')
$evm.root['ae_next_state'] = 'Finished'
$evm.log(:info, 'Ansible job returned a VM')
# need to address parenting here
rescue => err
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.