Rundeck options

1,831 views
Skip to first unread message

h4n...@gmail.com

unread,
Nov 26, 2018, 11:31:36 AM11/26/18
to rundeck-discuss
Hi 

I need to set some options dynamically 
The idea is when I select the option "VM" + I choose the choice "disable" in the second option "action" = the option "port" will automatically be fulfilled with the right port 
any help ?

here you are my xml file

Thanks
 
cascading_option.xml

rac...@rundeck.com

unread,
Nov 26, 2018, 12:19:43 PM11/26/18
to rundeck-discuss
Hi,

You can use casacade remote options, please check this for that:


Regards!

han roy

unread,
Nov 26, 2018, 2:33:56 PM11/26/18
to rundeck...@googlegroups.com
I read the documentation which is not very clear! 

--
You received this message because you are subscribed to the Google Groups "rundeck-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rundeck-discu...@googlegroups.com.
To post to this group, send email to rundeck...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rundeck-discuss/abc5275b-6af3-4585-8ac6-9c21ba28cb8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rac...@rundeck.com

unread,
Nov 26, 2018, 5:02:16 PM11/26/18
to rundeck-discuss
Hi Han,

I make a little example that works for understanding this :-)

Look:

In this example, you have two kinds of virtual machines: Linux and Windows.

Linux machines have two distributions: Fedora and Ubuntu, and Windows have two versions: Windows 10 and Windows Server...

Fedora have three versions: 27, 28 and 29, Ubuntu three versions: 16.04, 17.10 and 18.10, Windows 10 have three version: Home, Pro, and Ultimate, finally the Windows server have two versions: Core and Pro.

In the first option (when you define the two kinds of virtual machines) you can define the JSON file with full path like: file:/home/user/Rundeck/v3.0.7/projects/ProjectOPTIONS/DynamicOptions/VM.json

In the second you may define the option that depends on the previous option, like: file:/home/user/Rundeck/v3.0.7/projects/ProjectOPTIONS/DynamicOptions/${option.VM.value} <- see that we call of first option.

And in the third option you may define the option of the previous option, like: file:/home/user/Rundeck/v3.0.7/projects/ProjectOPTIONS/DynamicOptions/${option.actions.value} <- see that we call the second option

But in the JSON file you can call the "sub-options" stored in JSON file, for example in the VM.json you need put:

[
   
{"name":"Linux", "value":"linux.json"},
   
{"name":"Windows",  "value":"windows.json"}
]

See that value is the others JSON files: linux.json and windows.json, that may be created like:

linux.json

[
   
{"name":"fedora", "value":"fedoras.json"},
   
{"name":"ubuntus",  "value":"ubuntus.json"}
]

windows.json:

[
   
{"name":"windowsDesk", "value":"windsk.json"},
   
{"name":"windowsSrv",  "value":"winsrv.json"}
]

See that each JSON call other JSON files: fedoras.json, ubuntus.json, windsdk.json, and winsrv.json:

fedoras.json:

[
   
{"name":"v27","value":"27"},
   
{"name":"v28", "value":"28"},
   
{"name":"v29", "value":"29"}
]

ubuntus.json:

[
   
{"name":"16.04","value":"16"},
   
{"name":"17.10", "value":"17"},
   
{"name":"18.10", "value":"18"}
]

ubuntus.json:

[
   
{"name":"16.04","value":"16"},
   
{"name":"17.10", "value":"17"},
   
{"name":"18.10", "value":"18"}
]

windsk.json:

[
   
{"name":"Windows 10 Home","value":"win10home"},
   
{"name":"Windows 10 Pro", "value":"win10pro"},
   
{"name":"Windows 10 Ultimate", "value":"win10ult"}
]

winsrv.json:

[
   
{"name":"Windows 2016 Core","value":"win2k16core"},
   
{"name":"Windows 2016 Pro", "value":"win2k16pro"}
]

Here the job defintion of this example:

<joblist>
 
<job>
   
<context>
     
<options preserveOrder='true'>
       
<option enforcedvalues='true' name='VM' required='true' valuesUrl='file:/home/user/Rundeck/v3.0.7/projects/ProjectOPTIONS/DynamicOptions/VM.json' />
       
<option enforcedvalues='true' name='actions' value='disable' valuesUrl='file:/home/user/Rundeck/v3.0.7/projects/ProjectOPTIONS/DynamicOptions/${option.VM.value}' />
       
<option enforcedvalues='true' name='port' valuesUrl='file:/home/user/Rundeck/v3.0.7/projects/ProjectOPTIONS/DynamicOptions/${option.actions.value}' />
     
</options>
   
</context>
   
<defaultTab>output</defaultTab>
   
<description></description>
   
<executionEnabled>true</executionEnabled>
   
<id>1be216bc-7cca-4568-8476-ee770895c68e</id>
   
<loglevel>INFO</loglevel>
   
<name>cascading option</name>
   
<nodeFilterEditable>false</nodeFilterEditable>
   
<scheduleEnabled>true</scheduleEnabled>
   
<sequence keepgoing='false' strategy='node-first'>
     
<command>
       
<exec>echo $RD_OPTION_ACTION</exec>
     
</command>
     
<command>
       
<exec>echo $RD_OPTION_VM</exec>
     
</command>
     
<command>
       
<exec>echo $RD_OPTION_PORT</exec>
     
</command>
   
</sequence>
   
<uuid>1be216bc-7cca-4568-8476-ee770895c68e</uuid>
 
</job>
</joblist>

At moment of import take care the value of "Allowed Values > Remote URL" field match the route of your project (valuesUrl tag in the job definition)

Hope it helps!

h4n...@gmail.com

unread,
Nov 27, 2018, 11:53:57 AM11/27/18
to rundeck-discuss
Thank you for your precious help.
It works but not exactly as I want.

here you are my xml file and the content of my json files
It's possible that the option "port" depends of 2 other options "action" and "product" ? 

product.json
[
    {"name":"ps", "value":"prod1.json"},
    {"name":"scd",  "value":"prod2.json"}
]

prod1.json
[
    {"name":"prod-web1","value":"prod-web1"},
    {"name":"prod-web2", "value":"prod-web2"}
]

prod2.json
[
    {"name":"prod-sa1","value":"prod-sa1"},
    {"name":"prod-sa2", "value":"prod-sa2"}
]

action.json
[
   {"name":"Disable", "value":"disable.json"},
   {"name":"Enable",  "value":"enable.json"}
]

disable.json
[
    {"name":"443", "value":"443.json"},
    {"name":"80",  "value":"80.json"}
]

enable.json
[
    {"name":"none", "value":"none"}
]

443.json
[
    {"name":"pm", "value":"prod1.json"}
]

80.json
[
    {"name":"scd", "value":"prod2.json"}
]


Thanks in advance for your help,
cascading_option3.xml

fernand...@gmail.com

unread,
Jul 8, 2020, 8:39:45 AM7/8/20
to rundeck-discuss
I know this is an old thread ... but has anyone had any luck passing on file input option field value ( e.g. filename ) as part of the URL ? 

I have one case where i would need to pass the filename within the URL . e.g. : 

https://server.com/cgi-script.cgi?${file.myfileoption.filename}

Tried a few different formats , but none of them seems to work .... 

file.myfileoption.filename.value
option.myfileoption.value
etc etc  



rac...@rundeck.com

unread,
Jul 8, 2020, 1:41:27 PM7/8/20
to rundeck-discuss

Hi Fernando,

Following this message: https://groups.google.com/g/rundeck-discuss/c/5pZza15s_sc/m/5in41OtLHgAJ

I leave this example to test:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='myfile' type='file' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>211ae713-ec3e-479e-bcd3-7870c1c2e20b</id>
    <loglevel>INFO</loglevel>
    <name>FilenameAsName</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <description>get the filename for debug</description>
        <exec>echo ${file.myfile.fileName}</exec>
      </command>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[curl -X GET "https://httpbin.org/@file.myfile.fileName@" -H  "accept: application/json"]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>211ae713-ec3e-479e-bcd3-7870c1c2e20b</uuid>
  </job>
</joblist>

Just need a file with “ip” as a name to test successfully.

Fernando Hafner

unread,
Jul 9, 2020, 8:43:00 AM7/9/20
to rundeck...@googlegroups.com
Thanks for the example! 

But i'm afraid my case is a little different . My file is uploaded as a file option type, so I would need to reference that file as a value in other options - dynamically.

The relevant parts from my job definition as shown below ... my goal here is to add the the file name from component_list_file as part of the valueUrl in the Components option.

Unfortunately the RD documentation is rather fuzzy when it comes to using cascading remote options :( 

  <context>
      <options preserveOrder='true'>
        <option enforcedvalues='true' name='release' required='true' valuesUrl='http://localhost/cgi-bin/rd-release-branches.cgi'>
          <label>Release</label>
        </option>
        <option enforcedvalues='true' name='env' required='true' values='bos,den' valuesListDelimiter=','>
          <description> * **Ignored** when component.lst file is specified **and** `component:environment:build` format is used.</description>
          <label>Environment</label>
        </option>
        <option enforcedvalues='true' name='Components' valuesUrl='http://localhost/cgi-bin/rd-component-prod.cgi?${option.env.value},${option.release.value}'>
          <description>* **Ignored** when component .lst file is specified</description>
          <label>Components</label>
        </option>
        <option enforcedvalues='true' name='Build' valuesUrl='http://localhost/cgi-bin/rd-build-prod.cgi?${option.Components.value},${option.component_list_file.value}'>
          <description>* **Ignored** when component .lst file is specified</description>
          <label>Build</label>
        </option>
        <option name='component_list_file' type='file'>
          <description>.lst file with a `component::build` or `component:environment:build` format</description>
          <label>Component .lst file</label>
        </option>
      </options>
    </context>






--
Att.
Fernando Hafner

rac...@rundeck.com

unread,
Jul 9, 2020, 12:21:11 PM7/9/20
to rundeck-discuss

Hi Fernando,

I see, this is because rundeck won’t know the file name until the job runs, a good way to do that is “build” a URL with that name on any data variable (so, your “remote URL option” is the data variable now).

I leave an example, feel free to modify it if you like.

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='myfile' required='true' type='file' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>2cf3872e-30e8-465b-82fd-fcb046c20ba3</id>
    <loglevel>INFO</loglevel>
    <name>HelloWorld</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <description>build your "url" using that name and storage as data value</description>
        <exec>echo "MYURL=https://httpbin.org/${file.myfile.fileName}"</exec>
        <plugins>
          <LogFilter type='key-value-data'>
            <config>
              <invalidKeyPattern>\s|\$|\{|\}|\\</invalidKeyPattern>
              <logData>true</logData>
              <regex>^(MYURL)\s*=\s*(.+)$</regex>
            </config>
          </LogFilter>
        </plugins>
      </command>
      <command>
        <description>Now, you can do anything with that data value.</description>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[curl -X GET "@data.MYURL@" -H  "accept: application/json"]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>2cf3872e-30e8-465b-82fd-fcb046c20ba3</uuid>
  </job>
</joblist>

You can learn more about data values here:

https://docs.rundeck.com/docs/manual/log-filters/key-value-data.html#usage

Hope it helps!

Reply all
Reply to author
Forward
0 new messages