Check provisioning state in ManageIQ with Foreman

Posted by cjung on Wed, Jun 10, 2015

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:

1foreman_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:

1json_parse = JSON.parse(rest_result)
2hostid = json_parse['id'].to_s
3
4$evm.log("info", "Storing Foreman host ID of new VM: #{hostid}")
5prov.set_option(:hostid,hostid)