Running an Embedded Ansible Playbook method as part of an Automate State Machine

Use Case: Provision a VM using CFME and then run an Ansible Playbook on the newly provisioned VM.

  • Provision a VM thats gets an ip address. (vmware tools installed)Ansible vmware tools installed

  • Update the State Machine and add 2 steps (WaitForIP and Playbook)

  • Use METHOD:: syntax in your State Machine for WaitForIp:

  • If you don’t use the WaitForIp method the VM will not be ready and the Playbook will fail. The WaitForIp method will retry until the VM is ready.

Ansible Host field value

       -  For Cloud: ${/#miq_provision.destination.floating_ip_addresses.first}

Ansible Cloud host field value

1 Like

What’s in mk_sample_playbook? Why don’t you use /AutomationManagement/AnsibleTower/Operations/Statemachines/Job/default ?


My use case is: If you want to have CFME provision a VM and then run a playbook as part of the provisioning workflow.

mk_sample_playbook is a very simple playbook which requires some input values to be passed to it. If you just wanted to run this playbook on an existing VM, you could setup a service and run it using /AutomationManagement/AnsibleTower/Operations/Statemachines/Job/default.

Using the METHOD:: in a state allows you to directly call a method without having to have an instance.
In this example we use the method in a different location hence you need to use the ‘dot’ notation for the method name at the end.


1 Like

Thanks for putting this out here. This was puzzling me for days.


Hi guys,

How do you pass input parameters to your ansible playbook method in this case?
I have defined method which calls ansible playbook which requires passing information gathered from service request.

By this link:
I have found that Input Parameters are passed as extra_vars to ansible playbook. But how to map request ($evm.root[‘dialog_*’]) to this ansible method?

Thanks in advance!

You can use the standard substitution syntax, so for example to pass in the provision request and task IDs you could use the following two input parameters:

You playbook could use these to update the provisioning task’s options hash for example, maybe with the values retrieved from an IPAM solution:

  - debug: var=miq_provision_id
  - debug: var=miq_provision_request_id

  - name: Update Task with New IP and Hostname Information
      url: "{{ manageiq.api_url }}/api/provision_requests/{{ miq_provision_request_id }}/request_tasks/{{ miq_provision_id }}"
      method: POST
      body_format: json
        action: edit
            addr_mode: ["static", "Static"]
            ip_addr: "{{ ip_addr }}"
            subnet_mask: "{{ netmask }}"
            gateway: "{{ gateway }}"
      validate_certs: no
        X-Auth-Token: "{{ manageiq.api_token }}"
      body_format: json
      status_code: 200
1 Like

Hi Peter,

Thanks for detailed response and for a good example. I was able to get all the details of request and associated task. Although it requires more manipulations and additional rest api calls rather than passing directly bunch of parameters, it works very well!