How to pass a servicedialog value to a ruby script

automate

#1

Hey everyone

So i want to pass a variable (string) from the service dialog to a ruby script.
This is the only variable in the dialog. This variable is for example: “KL2_VL4004”
I called it “vlan” and i can see in the automation logs that the variable is read succesfully under the name: “dialog_vlan”.
However i can not pass it to a ruby script (which is executed while provisioning).
These are the things I’ve tried:
vlan = $evm.root[“dialog_vlan”]
vlan = $evm.root[“vlan”]
vlan = $evm.root[‘option_0_vlan’]
vlan = $evm.root[‘option_0_dialog_vlan’]
vlan = $evm.root[‘miq_provision’].get_option(‘dialog_vlan’)
vlan = $evm.root[‘miq_provision’].get_option(‘vlan’)
vlan = $evm.object[“dialog_vlan”]
vlan = $evm.object[‘vlan’]
vlan = dialog_options[‘dialog_vlan’]

Does anyone know how to do this?
Thanks in advance.


#2

It depends on the context, is the service dialog being displayed from a custom button, or from a service catalog? If the latter, which type of service (i.e. Ansible playbook, VM provision etc), and at which point in the workflow do you want to read the variable, (i.e. service provision state machine, VM provision state machine, etc)

pemcg


#3

@pemcg Thanks for the reply.
So i added a custom service dialog named “vlan” with only one input field where the enduser can define his/her vlan-name. This dialog gets called when you want to provision a new vm from the service catalog. I’m using vmware and the ruby script i made gets called when the vm is getting provisioned


#4

ok, then I’d expect your dialog value to be accessible as $evm.root['miq_provision'].options[:dialog_vlan] at this point in the workflow. You should be able to retrieve it using $evm.root['miq_provision'].get_option(:dialog_vlan).

You might find it enlightening to call object_walker in this situation as that will list all the values that are visible/accessible at the point in your state machine from which it is called.

Instructions for use are:

  1. Install the ‘Investigative_Debugging’ automate domain from https://github.com/pemcg/object_walker (you can install this directly as a git importable domain, or download the investigative_debugging.zip file and install it)
  2. Install the object_walker_reader.rb script onto your ManageIQ/CloudForms appliance using rpm -ivh https://github.com/pemcg/object_walker/raw/master/object_walker_reader-1.9-1.noarch.rpm
  3. From your AcquireIPAddress state in your state machine, call /Discovery/ObjectWalker/object_walker, and order your service so that the workflow is exercised and the method runs.
  4. From a command prompt, run object_walker_reader.rb to format & view the output

Hope this helps,
pemcg


#5

@pemcg I just tried your method and it works, Thanks for the help :slight_smile:
I’m also definitely going to try the object_walker method tomorrow