Rundeck 未为使用不同 ssh 端口的远程执行设置环境变量 [英] Rundeck not setting up environment variable for remote execution with different ssh port

查看:22
本文介绍了Rundeck 未为使用不同 ssh 端口的远程执行设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rundeck 将传递给作业的所有选项设置为环境变量,如 $RD_OPTION_*,但是当在具有不同 ssh 端口的远程节点中执行作业时,它不会设置这些变量.脚本成功登录到远程节点,但没有环境变量.请帮我解决.

示例作业定义:

<工作><上下文><options preserveOrder='true'><option name='option1' required='true'/></选项></上下文><描述>工作描述</描述><调度><excludePrecedence>true</excludePrecedence><keepgoing>false</keepgoing><rankOrder>升序</rankOrder><threadcount>1</threadcount></调度><executionEnabled>true</executionEnabled><id>id</id><loglevel>调试</loglevel><name>工作名称</name><节点过滤器><filter>名称:remote_node</filter></nodefilters><nodesSelectedByDefault>true</nodesSelectedByDefault><通知><失败时><email attachLog='true' receivers='abcdef@xyz.com' subject='job failure :('/></onfailure><成功><电子邮件收件人='abcdef@xyz.com'主题='工作成功'/></成功></通知><scheduleEnabled>true</scheduleEnabled><sequence keepgoing='false' strategy='step-first'><命令><exec>python path/to/script.py $RD_OPTION_OPTION1 >/path/to/logfile_$RD_JOB_EXECID.log 2>&1</exec></命令><命令><exec>java -jar path/to/jarfile.jar ${option.option1} >>/path/to/logfile_${job.execid}.log"2>&1</exec></命令></序列><uuid>job-uuid</uuid></工作></joblist><!--这里选择远程节点执行时,$RD_JOB_EXECID,${job.execid},${option.option1},$RD_OPTION_OPTION1 未设置为环境变量但是在本地执行时,相同的变量被设置为环境变量.Rundeck 以用户身份成功登录到远程节点.由于尚未设置 $RD_JOB_EXECID,因此在远程节点的/path/to/logfile_.log 文件中可以看到日志条目.选项@option.option1@ 工作正常,因为它们在执行命令之前已被 rundeck 替换.Rundeck 详细信息:用户: rundeck外壳:/bin/nologinrundeck 以普通用户身份登录远程服务器,该用户拥有执行所有这些脚本/jar 的所有权限.-->

注意:

Rundeck 在具有不同 ssh 端口的远程实例上执行时不会设置环境变量.在这种情况下,端口是 2808,并且在 resources.xml 中更新为 123.456.789.0:2808.Rundeck 登录服务器并成功执行脚本(没有环境变量).远程实例 sshd_config 已配置为接受 RD_* 变量.使用端口 22 登录时设置和访问相同的环境变量.

解决方案

我认为你混淆了 Rundeck 命令参数Rundeck 环境变量

这是命令、脚本参数和作业参考参数":${job.execid}

顾名思义,您可以将其用作命令参数.就像您在工作定义中所做的一样.

这是一个环境变量":$RD_JOB_EXECID

无需任何设置,如果您在 Rundeck 服务器本身上运行作业,两者都可以正常工作,但如果您想将作业分派到节点,$RD_JOB_EXECID 将无法开箱即用.

<块引用>

通过远程命令调度传递环境变量,它是需要在远程端正确配置 SSH 服务器.见sshd_config(5)"

XML 中的工作定义

<工作><上下文><options preserveOrder='true'><option name='nodeFilter'/></选项></上下文><描述></描述><调度><excludePrecedence>true</excludePrecedence><keepgoing>false</keepgoing><rankOrder>升序</rankOrder><threadcount>1</threadcount></调度><executionEnabled>true</executionEnabled><组>测试</组><id>63b6f283-39b2-479d-bba9-b1742bc2ea53</id><loglevel>信息</loglevel><name>测试 rundeck 作业上下文</name><节点过滤器><filter>${option.nodeFilter}</filter></nodefilters><nodesSelectedByDefault>true</nodesSelectedByDefault><scheduleEnabled>true</scheduleEnabled><sequence keepgoing='false' strategy='node-first'><命令><脚本><![CDATA[#!/usr/bin/python导入系统打印我知道 ENV_VAR 不能作为命令行参数 %s" % sys.argv]]></脚本><脚本参数>&gt;${job.execid}&lt; &gt;$RD_JOB_EXECID&lt;"</scriptargs></命令><命令><脚本><![CDATA[#!/bin/bashecho "但它适用于 Bash"回声 $RD_JOB_ID回声 $RD_JOB_EXECIDecho "sshd 监听哪个端口?"须藤 netstat -tulpn |grep 2808]]></script><脚本参数/></命令></序列><uuid>63b6f283-39b2-479d-bba9-b1742bc2ea53</uuid></工作></joblist>

Rundeck setsup all the options passed to a job as environment variable like $RD_OPTION_* but it is not setting up those variables when a job is executed in remote node with different ssh port. The script logs into remote node successfully but environment variables are not there. Please help me with a solution.

Sample Job definition:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='option1' required='true' />
      </options>
    </context>
    <description>job description</description>
    <dispatch>
      <excludePrecedence>true</excludePrecedence>
      <keepgoing>false</keepgoing>
      <rankOrder>ascending</rankOrder>
      <threadcount>1</threadcount>
    </dispatch>
    <executionEnabled>true</executionEnabled>
    <id>id</id>
    <loglevel>DEBUG</loglevel>
    <name>job name</name>
    <nodefilters>
      <filter>name: remote_node</filter>
    </nodefilters>
    <nodesSelectedByDefault>true</nodesSelectedByDefault>
    <notification>
      <onfailure>
        <email attachLog='true' recipients='abcdef@xyz.com' subject='job failure :(' />
      </onfailure>
      <onsuccess>
        <email recipients='abcdef@xyz.com' subject='job succes' />
      </onsuccess>
    </notification>
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='step-first'>
      <command>
        <exec>python path/to/script.py $RD_OPTION_OPTION1 > /path/to/logfile_$RD_JOB_EXECID.log 2>&1</exec>
      </command>
      <command>
        <exec>java -jar path/to/jarfile.jar ${option.option1} >> "/path/to/logfile_${job.execid}.log" 2>&1</exec>
      </command>
    </sequence>
    <uuid>job-uuid</uuid>
  </job>
</joblist>

<!-- 
Here
$RD_JOB_EXECID,${job.execid},${option.option1},$RD_OPTION_OPTION1 are not being setup as environment variables when remote node is selected for execution
but the same variables are set up as environment variables when executed locally.
Rundeck logins to the remote node as user successfully.

Log entries are seen in /path/to/logfile_.log file in remote node since $RD_JOB_EXECID has not been set up.

the options @option.option1@ are working fine since they have been replaced by rundeck before executing command.

Rundeck details:
    user: rundeck
    shell: /bin/nologin
    
    rundeck logs into remote server as normal user who has all permissions to execute all these scripts/jars.

-->

Note:

Rundeck is not setting up environment variables when executed on remote instance with different ssh port. In this case port is 2808 and the same has been updated in resources.xml as 123.456.789.0:2808. Rundeck logs into server and executes scripts successfully (without environment variables). Remote instance sshd_config has been configured to accept RD_* variables. The same Environment variables are set up and accessed when logged in using port 22.

解决方案

I think you mixed up Rundeck commands arguments and Rundeck environment variables

This is a "Commands, Script Arguments and Job Reference Arguments": ${job.execid}

As its name states, you can use it as a commands arguments. Just like what you did in your job definition.

This is a "Environment Variables": $RD_JOB_EXECID

Without any setup, both work fine if you are running the job on Rundeck server itself, but if you want to dispatch your job to a node, $RD_JOB_EXECID will not work out of box.

To pass environment variables through remote command dispatches, it is required to properly configure the SSH server on the remote end. See the AcceptEnv directive in the "sshd_config(5)" manual page for instructions.

Use a wild card pattern to permit RD_ prefixed variables to provide open access to Rundeck generated environment variables.

 Example in sshd_config:

 # pass Rundeck variables 
 AcceptEnv RD_*

Rundeck SSH Plugins

On Rundeck Server

Make sure you have SendEnv RD_* set in ssh_config

For your usecase, ${job.execid},${option.option1} would works perfect with out mess around with sshd_config


It DOES work on differect SSH port.

Job Definition in XML

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='nodeFilter' />
      </options>
    </context>
    <description></description>
    <dispatch>
      <excludePrecedence>true</excludePrecedence>
      <keepgoing>false</keepgoing>
      <rankOrder>ascending</rankOrder>
      <threadcount>1</threadcount>
    </dispatch>
    <executionEnabled>true</executionEnabled>
    <group>TEST</group>
    <id>63b6f283-39b2-479d-bba9-b1742bc2ea53</id>
    <loglevel>INFO</loglevel>
    <name>test rundeck job context</name>
    <nodefilters>
      <filter>${option.nodeFilter}</filter>
    </nodefilters>
    <nodesSelectedByDefault>true</nodesSelectedByDefault>
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <script><![CDATA[#!/usr/bin/python
import sys
print "I know ENV_VAR will not work as command line arguments %s " % sys.argv
]]></script>
        <scriptargs> "&gt;${job.execid}&lt; &gt;$RD_JOB_EXECID&lt;"</scriptargs>
      </command>
      <command>
        <script><![CDATA[#!/bin/bash
echo "But it works in Bash"
echo $RD_JOB_ID
echo $RD_JOB_EXECID

echo "Which port does sshd listening on?"
sudo netstat -tulpn | grep 2808]]></script>
        <scriptargs />
      </command>
    </sequence>
    <uuid>63b6f283-39b2-479d-bba9-b1742bc2ea53</uuid>
  </job>
</joblist>

这篇关于Rundeck 未为使用不同 ssh 端口的远程执行设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆