Search code examples
ansiblerundeckproxmox

Rundeck controlling Proxmox through REST API


I'm completely new to Rundeck, which I installed with Docker. My goal is to control a Proxmox cluster with its APIs. How can I do that? Maybe with Ansible? Do you have pointers for me?

Thanks in advance

Regards


Solution

  • Ansible isn't necessary for that. You can create a workflow with HTTP Workflow step plugin to send the API request to your Proxmox host (download the jar file from here and put it on the libext directory or use the plugin manager to install it [ Gear icon > Plugins > Find Plugins > Search "HTTP Workflow Step" and click on "Install" button ], you don't need to restart the instance).

    Alternatively, you can create a workflow with a script-step that the Proxmox API call using cURL directly. Also, you can pass options dynamically to your script step using @option.myoption@ syntax (for example, pass the actions from an options list).

    I leave a job definition example with both ways to do this (using httpbin.org service and passing a couple of options to both steps).

    <joblist>
      <job>
        <context>
          <options preserveOrder='true'>
            <option name='action' value='anything' />
            <option name='host' value='httpbin.org' />
          </options>
        </context>
        <defaultTab>nodes</defaultTab>
        <description></description>
        <executionEnabled>true</executionEnabled>
        <id>da60f0f8-d3d1-4f6d-b01e-704e00fa2ae8</id>
        <loglevel>INFO</loglevel>
        <name>APICallExample</name>
        <nodeFilterEditable>false</nodeFilterEditable>
        <plugins />
        <scheduleEnabled>true</scheduleEnabled>
        <sequence keepgoing='false' strategy='node-first'>
          <command>
            <description>Example using http workflow step plugin</description>
            <step-plugin type='edu.ohio.ais.rundeck.HttpWorkflowStepPlugin'>
              <configuration>
                <entry key='authentication' value='None' />
                <entry key='checkResponseCode' value='true' />
                <entry key='headers' value='{"Accept": "application/json"}' />
                <entry key='method' value='POST' />
                <entry key='printResponse' value='true' />
                <entry key='printResponseToFile' value='false' />
                <entry key='proxySettings' value='false' />
                <entry key='remoteUrl' value='https://${option.host}/${option.action}' />
                <entry key='responseCode' value='200' />
                <entry key='sslVerify' value='false' />
                <entry key='timeout' value='30000' />
              </configuration>
            </step-plugin>
          </command>
          <command>
            <description>Example using script-step</description>
            <fileExtension>.sh</fileExtension>
            <script><![CDATA[curl -X POST "https://@option.host@/@option.action@" -H  "accept: application/json"]]></script>
            <scriptargs />
            <scriptinterpreter>/bin/bash</scriptinterpreter>
          </command>
        </sequence>
        <uuid>da60f0f8-d3d1-4f6d-b01e-704e00fa2ae8</uuid>
      </job>
    </joblist>