Rundeck - loop on referenced job

Viewed 23

I break my head with a problem of referenced job on my workflow. I'm not sur this is possible with Rundeck :

I have a job who call a second. I want run this second for all nodes but only over one server.

With this exemple maybe it's more simple to understand:

Workflow : Select Nodes
Referenced job 1

NodeA > Website www.exempleA.com < restore DB with default value  
NodeB > Website www.exempleB.com < restore DB with default value  
NodeC > Website www.exempleC.com < restore DB with default value  
NodeD > Website www.exempleD.com < restore DB with default value 

This run perfectly

Referenced Job 2 : Use Cypress server to test websites. Node filter have only Cypress server.

NodeE > Cypress -url https://${node.name} = NodeA > www.exempleA.com  
NodeE > Cypress -url https://${node.name} = NodeB > www.exempleB.com  
NodeE > Cypress -url https://${node.name} = NodeC > www.exempleC.com  
NodeE > Cypress -url https://${node.name} = NodeD > www.exempleD.com 

So I want to make a loop with a referenced job who execute on only one server but for all nodes name.

Someone know if this configuration is possible with Rundeck ?

Thank you for your knowledge.

Erwan

1 Answers

An excellent way to do that is to play with parent job options in two ways: first, against the first child job as a node filter (to dispatch to remote nodes), and second, against the second child job (to create an array and run the Cypress command in a bash loop).

Here is an example to test.

Parent Job. Contains an option that should be used for child jobs.

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: db051872-7d5f-4506-bd49-17719af9785b
  loglevel: INFO
  name: ParentJob
  nodeFilterEditable: false
  options:
  - name: nodes
    value: node00 node01 node02
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - jobref:
        args: -myfilter ${option.nodes}
        group: ''
        name: FirstChildJob
        nodeStep: 'true'
        uuid: f7271fc4-3ccb-41a5-9de4-a12e65093a3d
    - jobref:
        args: -myarray ${option.nodes}
        childNodes: true
        group: ''
        name: SecondChildJob
        nodeStep: 'true'
        uuid: 1b8b1d82-a8dc-4949-9245-e973a8c37f5a
    keepgoing: false
    strategy: sequential
  uuid: db051872-7d5f-4506-bd49-17719af9785b

First Child Job. Takes the parent job option and uses that as a job filter, the node filter is an own option called ${option.myfilter}.

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: f7271fc4-3ccb-41a5-9de4-a12e65093a3d
  loglevel: INFO
  name: FirstChildJob
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: ${option.myfilter}
  nodesSelectedByDefault: true
  options:
  - name: myfilter
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - exec: echo "hi"
    keepgoing: false
    strategy: node-first
  uuid: f7271fc4-3ccb-41a5-9de4-a12e65093a3d

Second Child Job. Contains an inline-script step that takes the parent's job option as an array and runs in a bash loop.

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: 1b8b1d82-a8dc-4949-9245-e973a8c37f5a
  loglevel: INFO
  name: SecondChildJob
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: 'name: node02'
  nodesSelectedByDefault: true
  options:
  - name: myarray
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - script: "#!/bin/bash\narray=(@option.myarray@)\nfor i in \"${array[@]}\"\ndo\n\
        \techo \"execute $i\"\ndone"
    keepgoing: false
    strategy: node-first
  uuid: 1b8b1d82-a8dc-4949-9245-e973a8c37f5a

Here is the loop script (inside the second child job as inline-script):

#!/bin/bash
array=(@option.myarray@)
for i in "${array[@]}"
do
    echo "$i"
done

And here you can see the result.

Related