Check provisioning state in ManageIQ with Foreman

Posted by Christian Jung on Wed, Jun 10, 2015
In CloudForms, IT, ManageIQ, The Foreman
Tags

If you’re using The Foreman for provisioning VMs, you might want the state machine to proceed only if the puppet run was completed successfully. I wrote a script which checks the puppet state of a given VM via Foreman’s API. It can be found on Github.

To make this script work, the hostid of the provisioned VM has to be stored as an provisioning option. The following line in the script, retrieves the hostid:

foreman_host_id <span class="pl-k">=</span> prov.get_option(<span class="pl-c1">:hostid</span>)

If this variable is nil, the status check will fail. I updated the register_foreman script, which can also be found on Github, accordingly:

json_parse = JSON.parse(rest_result)
hostid = json_parse['id'].to_s

$evm.log("info", "Storing Foreman host ID of new VM: #{hostid}")
prov.set_option(:hostid,hostid)