Ansible Tower integration has been supported by CloudForms for a while. Any Tower job template can be presented as a service item in CloudForms, allowing users to easily run automated tasks, while taking advantage of capabilities like its built in RBAC.

Example automation might be virtual machine provisioning and in this case using CloudForms, we need to associate the newly provisioned VMs with the CloudForms service that deployed them. This is useful in order to manage them once deployed, like power operations and remote console. Also known as day two operations.

Of course CloudForms can provision VMs natively on supported providers but it may make sense to use an Ansible playbook to do the provisioning instead, perhaps making use of existing tried and tested automation.

This service association or linking, can be automated and thanks to John Hardy, here is an example using CloudForms Embedded Ansible. However, achieving the same result with Ansible Tower has some additional challenges.

In this Ansible Tower example, we're deploying a RHV virtual machine from a CloudForms service which launches a Tower Job Template. We need to add the newly created VM to the resulting CloudForms service in My Services for day two operations.


Ansible Tower:

  • Project (with the playbook)
  • Provider credentials (RHV in this example)
  • Custom credentials (for CloudForms' API)
  • Playbook Job Template (configured with both credentials and survey with service_id)


  • Ansible Tower type Catalog Item for the Job Template
  • Automate update to insert the service_id as an extra var


Here is the new playbook which includes the following tasks:

  • Retrieves an authorisation token from CloudForms
  • Sets the provider URL (for refresh post provision)
  • Sets the service URL (based on the service_id extra var)
  • Connects to RHV and creates the new VM
  • Stores the new VM's ID
  • Refreshes the CloudForms provider to pickup the new VM in the inventory
  • Retrieves the new VM's href from CloudForms
  • Registers the new VM to the CloudForms service

Ansible Tower


We need two credentials, firstly RHV to create the VM. We can use the built in Ansible Tower credentials for RHV since the oVirt module knows what to do.

Secondly we need to create a custom credential type for use with the CloudForms API, since we're using the uri module and not a CloudForms specific module to connect with CloudForms.

We need to create the new credential type in Ansible Tower with the following configuration:

Input Configuration

  - type: string
    id: username
    label: CloudForms username
  - secret: true
    type: string
    id: password
    label: CloudForms password
  - username
  - password

Injector Configuration

  cf_pw: '{{ password }}'
  cf_user: '{{ username }}'

Finally, we need to create a custom credential using this new type. The new credential extra vars cf_pw and cf_user are used in the playbook

Job Template

Create a new job template based on the playbook, which should look something like this:

NOTE the addition of the two credentials.

Extra Vars

We need to specify a few environment specific variables too.

provider_id: 99000000000003
vm_template: RHEL6
cluster: Default


This must include the service_id prompt. In this example, we're also asking the vm_name.



Dynamically create this in CloudForms from the discovered Tower Job Template. To simplify the ordering process, all the elements can be configured as not visible, except vm_name in this example.

Catalog Item

Create an Ansible Tower Playbook type catalog item.


We need to automate the inclusion of the ID of the CloudForms service invoking the Tower job. Including this as an extra var is achieved by modifying the following Automate method:


Add the following line to the modify_job_options function:

job_options[:extra_vars]['service_id'] =

NOTE: Be sure to also modify the main function o that the modify_job_options function is called.


Finally, we can order the service item from the catalog.

And once deployed, the VM is visible under the new service in My Services.