我是 Rundeck 的新手。我希望能够将文件(作为必需选项)传递给 Rundeck 作业调用,然后让 Rundeck 上传该文件到远程节点,然后在远程节点上运行命令来处理该文件。这适用于默认节点,rundeck
但不适用于远程节点。
我有一个 Rundeck 实例(版本 3.0.21-20190424)在线并且成功与一个外部节点通信。文档解释如何获得文本选项通过 SSH 连接作为环境变量传递到远程节点,但没有说明如何获取文件传递给远程节点的选项。
这是我的职位定义:
- 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
这是在节点上运行的输出rundeck
:
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
这是在远程节点上运行的输出:
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`
显然,这可以通过多个步骤来完成,即将文件从 Rundeck 节点复制到目标节点,但这感觉就像 Rundeck 应该为我自动完成的事情。此外,这感觉像是一件很常见的事情,所以我不确定为什么我很难找到有关它的任何信息。
欢迎提出任何建议。
答案1
在您的项目配置中,将 SSH 设置为默认节点执行器,并将 SCP 设置为默认文件复制器。然后创建一个作业,其中包含文件复制步骤,后面跟着命令步骤(“执行远程命令”)。您还需要为项目设置适当的节点源。它看起来像这样:作业设置 - 工作流程
- 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