Service Catalog Item of type Ansible Playbook: Associate VM


I have configured a Service Catalog Item to trigger VM deployment via Ansible playbook. I see that in provisioned service there is a VMs section. Would it be possible to add provisioned machine to service from ansible?

Is anybody using Ansible Playbooks provisioning vs Automation State Machines/Ruby?
It seems like even Red Hat representatives advise to use more Ansible vs ruby as it’s more portable.

Thanks in advance,


Yes you can associate a newly provisioned VM (provisioned using embedded Ansible) with the service, using the Ansible manageiq_vmdb role, as follows:

  - name: Get the service object
      href: "{{ manageiq.service }}"
    register: service

  - name: Get the VM object
      href: "vms/18"
    register: vm

  - name: Add the VM to the service
      vmdb: "{{ service }}"
      action: add_resource
          href: "{{ vm.href }}"

The challenge is to get the new VM’s object id (in that example VMS/18). For this you need to trigger a provider refresh via the API and detect the new VM. There’s an example of doing that in the following playbook (note that playbook hard-codes the provider_id to “21000000000002” - yours will almost certainly be different):

Regarding the Ruby versus Ansible argument, my own personal opinion is that the out-of-the-box Ruby-based VM and service provisioning “just works”, i.e. VMs are linked into services as you’d expect, and the workflow is thoroughly tested. The advantage of Ansible is where you don’t have existing Ruby skills to modify the workflow, and Ansible/yaml is certainly easier to learn and understand than Ruby for a novice.

I’d be wary of the claim for portability though, because you still tend to need to write ManageIQ-specific playbooks, as that example shows when using the manageiq_vmdb role to link the VM to the service, finding the new VM ID, etc.

hope this helps,

Hi @pemcg,

Thanks for information and links to examples.

As of Ruby vs Ansible, I agree with you for vm provisioning as all vmware objects are accessible internally via evm. It’s easier to manipulate the data for placement and vm tagging after deployment. For external integrations, such as Netapp, Infoblox, Cisco in our case i think it’s better to go with ansible. As it already has many modules out of the box.

Best regards,