简体   繁体   中英

How can I run a job on Rundeck for each user in the list?

I want to create a scheduled job on Rundeck. Rundeck Job runs the script that does some staff for a single user I have in my list.

So job has an input parameter - username. I need to run that job for all users in my list, but not to process it in one job execution. I need a separate job execution for each user.

Providing an example to make it more clear:
For instance, I have 3 users: user1, user2, user3.

    
I have a job that does some processing for that users and running it with parameter (unsername). 
I need to create a scheduled job that will be run for each user.

 1. Running job with user1 parameter
 2. Running job with user2 parameter
 3. Running job with user3 parameter

Is there anyway to do that?

You can design a workflow with a list option to use on any step (like command, inline-script or script), I did an example with a list option (users) and example inline-script that do some action for each user, the job is scheduled.

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='users' required='true' value='alice,bob,charlie,david' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <executionEnabled>true</executionEnabled>
    <id>e62a25a0-b67c-4bb7-8721-c96b7e4cb9f5</id>
    <loglevel>INFO</loglevel>
    <name>JobEXAMPLE</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <schedule>
      <month month='*' />
      <time hour='12' minute='0' seconds='0' />
      <weekday day='*' />
      <year year='*' />
    </schedule>
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <fileExtension>.sh</fileExtension>
        <script><![CDATA[#!/bin/bash

myusers=@option.users@
Field_Separator=$IFS
 
# set comma as the internal field separator for the string list
IFS=,
for value in $myusers;
do
    echo "action for $value"
done
 
IFS=$Field_Separator]]></script>
        <scriptargs />
        <scriptinterpreter>/bin/bash</scriptinterpreter>
      </command>
    </sequence>
    <uuid>e62a25a0-b67c-4bb7-8721-c96b7e4cb9f5</uuid>
  </job>
</joblist>

Here the result.

Maybe this interest you. Also, data values work in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM