2

I'm new to Rundeck. I want to be able to pass a file (as a required option) to a Rundeck job invocation and then have Rundeck upload that file to a remote node and then also run a command on the remote node to do something with the file. This works with the default rundeck node but not a remote node.

I have a Rundeck instance (version 3.0.21-20190424) online and successfully communicating with one external node. The documentation explains how to get text options passed through an SSH connection as environment variables to the remote node but is silent on how to get a file option to be passed to the remote node.

This is my job definition:

- defaultTab: summary
  description: Test Job
  executionEnabled: true
  id: 62fdba6d-70c8-4174-9bab-dde364076e8c
  loglevel: INFO
  name: test2
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: .*
  nodesSelectedByDefault: true
  options:
  - description: This is an example of a text option.
    name: example_text_option
  - description: This is an example file option.
    name: example_file_option
    required: true
    type: file
  scheduleEnabled: true
  sequence:
    commands:
    - fileExtension: sh
      script: |-
        #!/usr/bin/env bash

        echo "hostname: $(hostname)"
        echo "PWD: $PWD"

        echo ----
        echo "RD_OPTION_EXAMPLE_FILE_OPTION (UUID): $RD_OPTION_EXAMPLE_FILE_OPTION"
        echo "RD_FILE_EXAMPLE_FILE_OPTION_FILENAME (Original file name): $RD_FILE_EXAMPLE_FILE_OPTION_FILENAME"
        echo "RD_FILE_EXAMPLE_FILE_OPTION_SHA (SHA256 has of file): $RD_FILE_EXAMPLE_FILE_OPTION_SHA"

        echo ----
        echo "option.example_file_option: @option.example_file_option@"
        echo "file.example_file_option: @file.example_file_option@"
        echo "file.example_file_option.fileName: @file.example_file_option.fileName@"
        echo "file.example_file_option.sha: @file.example_file_option.sha@"

        echo ----
        ls -l @file.example_file_option@
    keepgoing: false
    strategy: node-first
  uuid: 62fdba6d-70c8-4174-9bab-dde364076e8c

This is the output from running on the rundeck node:

hostname: rundeck
PWD: /home/rundeck
----
RD_OPTION_EXAMPLE_FILE_OPTION (UUID): 8c370949-51d8-467a-8f2d-b80774469e8b
RD_FILE_EXAMPLE_FILE_OPTION_FILENAME (Original file name): 2aOErzD.jpg
RD_FILE_EXAMPLE_FILE_OPTION_SHA (SHA256 has of file): b5e490d0f96d033367b8a4addef58b7e2904ea3c7465b2f801b600443ef562ec
----
option.example_file_option: 8c370949-51d8-467a-8f2d-b80774469e8b
file.example_file_option: /home/rundeck/var/upload/8c370949-51d8-467a-8f2d-b80774469e8b
file.example_file_option.fileName: 2aOErzD.jpg
file.example_file_option.sha: b5e490d0f96d033367b8a4addef58b7e2904ea3c7465b2f801b600443ef562ec
----
-rw-r--r-- 1 rundeck rundeck 115069 Sep  3 15:20 /home/rundeck/var/upload/8c370949-51d8-467a-8f2d-b80774469e8b

This is the output from running on the remote node:

hostname: test_node
PWD: /home/rundeck
----
RD_OPTION_EXAMPLE_FILE_OPTION (UUID): 8c370949-51d8-467a-8f2d-b80774469e8b
RD_FILE_EXAMPLE_FILE_OPTION_FILENAME (Original file name): 2aOErzD.jpg
RD_FILE_EXAMPLE_FILE_OPTION_SHA (SHA256 has of file): b5e490d0f96d033367b8a4addef58b7e2904ea3c7465b2f801b600443ef562ec
----
option.example_file_option: 8c370949-51d8-467a-8f2d-b80774469e8b
file.example_file_option: /home/rundeck/var/upload/8c370949-51d8-467a-8f2d-b80774469e8b
file.example_file_option.fileName: 2aOErzD.jpg
file.example_file_option.sha: b5e490d0f96d033367b8a4addef58b7e2904ea3c7465b2f801b600443ef562ec
----
ls: cannot access '/home/rundeck/var/upload/8c370949-51d8-467a-8f2d-b80774469e8b': No such file or directory
Failed: NonZeroResultCode: Remote command failed with exit status 2`

Obviously it's probably possible to do this in multiple steps, i.e. copy the file from the rundeck node to the destination node but this feels like the kind of thing Rundeck is supposed to be automating for me. Further, it feels like a very common thing to want to do so I'm not sure why I'm having such a hard time finding any info about it.

Any suggestions appreciated.

1
  • just as a throught mkdir -p /home/rundeck/var/upload/ – djdomi Sep 3 '19 at 22:18
1

In your project config, set up SSH as the default Node Executor and set up SCP as the default File Copier. Then create a job that has a File Copy step followed by a Command step ("Execute a remote command"). You will also need to set up an appropriate node source for the project. It looks like this: Job Setup - Workflow

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: c7579365-98a9-4503-8192-149e41bfd711
  loglevel: INFO
  name: Copy File
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: group:dev site:auburn service:bioraft3
  nodesSelectedByDefault: true
  options:
  - name: File
    type: file
  scheduleEnabled: true
  sequence:
    commands:
    - configuration:
        destinationPath: /tmp/${file.File.fileName}
        echo: 'true'
        recursive: 'false'
        sourcePath: ${file.File}
      nodeStep: true
      type: copyfile
    - exec: cat /tmp/${file.File.fileName}
    keepgoing: false
    strategy: node-first
  uuid: c7579365-98a9-4503-8192-149e41bfd711

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.