Preserve data in ManageIQ state machines

Posted by cjung on Mon, Mar 30, 2015

A state machine in ManageIQ or CloudForms can be used to describe a sequence of tasks executed during specific actions. A state machine offers logic for retries, error handling and can be easily created and optimised to accomplish complex tasks.

For quite some time there was a limitation in the state machine, if variables had to be carried between different stages (Bugzilla #1044175). It worked fine, until a state had to be re-executed (retry) which caused the “collect” feature to loose the data.

Since CloudForms 3.1 there are three new calls to store and retrieve data between different stages in a state machine:

  • state_var_exist?(var_name)

  • set_state_var(var_name, value)

  • get_state_var(var_name)


1if $evm.state_var_exist?("test_data")
2    test_data = $evm.get_state_var("test_data")
3    # TODO: Something interesting
5    # First time through, initialize data
6    $evm.set_state_var("test_data", 1)

Found this here: