The latest ManageIQ and CloudForms support calling Embedded Ansible Playbooks directly from a State (step) in a StateMachine (workflow).

This is useful but passing the extra vars to and between playbooks can be a challenge.

Various variables exist in the EVM Automate Workspace which can be used.

Additionally, the new manageiq-automate Ansible module means new variables can easily be created and shared between playbooks.

Workspace variables are specified using ${/#var} notation.

This example custom statemachine is called from a Generic service catalogue item.

statemachine

It creates an Amazon EC2 instance and passes the public IP address to the next playbook to install Apache.

Method Input Parameters

The first state in the custom statemachine uses dialogue values present in the workspace.

We can use method Input Parameters to pass variables into the playbook method like this:

inputparms

In this example, we're taking the dialogue value of vm_name and passing it into the method.

Playbook Limit

The second step uses a custom workspace variable as the Hosts limit. The variable is created by the playbook run in the first state.

Here's the first playbook's task that creates the variable:

- name: Save public_ip in $evm.root
  manageiq_automate:
    workspace: "{{ workspace }}"
    set_attribute:
      object: root
      attribute: public_ip
      value:  "{{ ec2.instances[0].public_ip }}"

The variable public_ip is specified as Hosts limit in the playbook method like this:

hosts

That's It

The playbooks and methods used in this example can be found here.