Search code examples
pythonpython-modulerundeck

Create Job using Rundeckrun?


Want to create a job using rundeckrun python module in Rundeck, I searched in their documentation, but couldn't find it.

Is there any other option to create a job using rundeckrun in Rundeck

Thanks for your attention.


Solution

  • This was recently posted in the rundeckrun repo: #17 (probably by you: @Naren). As I mentioned in the comments of that Github Issue, the Rundeck API doesn't provide a high level method of creating jobs so rundeckrun doesn't either... yet. :) However, the Rundeck API does provide a method of importing job definitions and rundeckrun provides a light wrapper around that endpoint. You can manipulate/create a job definition and import it. In fact, that's exactly what's done in the tests/__init__.py setup logic:

    test_job_id = uuid.uuid4()
    test_job_name = 'TestJobTest'
    test_job_proj = 'TestProjectTest'
    test_job_def_tmpl = """<joblist>
      <job>
        <id>{0}</id>
        <loglevel>INFO</loglevel>
        <sequence keepgoing='false' strategy='node-first'>
          <command>
            <node-step-plugin type='localexec'>
              <configuration>
                <entry key='command' value='echo "Hello World! (from:${{option.from}})"' />
              </configuration>
            </node-step-plugin>
          </command>
          <command>
            <node-step-plugin type='localexec'>
              <configuration>
                <entry key='command' value='sleep ${{option.sleep}}' />
              </configuration>
            </node-step-plugin>
          </command>
        </sequence>
        <description></description>
        <name>{1}</name>
        <context>
          <project>{2}</project>
          <options>
            <option name='from' value='Tester' />
            <option name='sleep' value='0' />
          </options>
        </context>
        <uuid>{0}</uuid>
      </job>
    </joblist>"""
    test_job_def = test_job_def_tmpl.format(test_job_id, test_job_name, test_job_proj)
    

    And then the creation of the job...

    def setup():
        rundeck_api.jobs_import(test_job_def, uuidOption='preserve')