从脚本步骤到内联 Ansible Playbook 的 Rundeck 变量 [英] Rundeck variable from script steps to Inline Ansible Playbook

查看:16
本文介绍了从脚本步骤到内联 Ansible Playbook 的 Rundeck 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 Web URL 下载一个文件并将其扩展到无法访问互联网的远程服务器.

I need to download a file from web URL and inflate into remote server, which does not have internet access.

  1. Rundeck 将文件下载到本地路径 wget,然后推送文件使用 SSH 连接到目标服务器
  2. Rundeck 在远程节点上执行脚本以膨胀使用上述步骤复制的文件和执行其他内务活动,(它是一个 bash shell 脚本)

我对 Rundeck 的使用知之甚少.

I am with very little knowledge on using Rundeck.

第一步,我已经完成了.文件从 URL 下载到 rundeck 并推送到目标服务器.

Step one, I have got it done. File is downloaded to rundeck from URL and pushed to destination server.

    [ -d "/apps/support/dump/CNRLS2" ]  && rm -r "/apps/support/dump/CNRLS2"
    echo "Creating workspace folder"
    mkdir -p /apps/support/dump/CNRLS2
    cd /apps/support/dump/CNRLS2

   export ArtifactURL="https://artifact.dummy.dummyurl.com/artifactory/generic-release/XRSL/CNRLS/develop/113/RLAWESOME-1379.tar.gz"
    echo "Downloading Artifact at $ArtifactURL from Artifactory"
    wget -q $ArtifactURL --no-check-certificate 
    export packageName=$(echo "${ArtifactURL##*/}")
    echo $packageName
    scp -r /apps/support/dump/CNRLS2/*.* yurtdxx67a@11.28.293.88:/xmodules/fixes/migreq/

这将我的包推送到远程服务器路径 /xmodules/fixes/migreq/

This pushed my package to remote server path /xmodules/fixes/migreq/

现在第二步

我正在运行内联 ansible 作为在目标节点上执行解包的下一步.ansible 转到目标节点并调用 unpack.sh ,我无法将上一步中的 packageName 值传递给内联 ansible.

I am running an inline ansible as the next step to perform the unpack on destination node. The ansible goes to destination node and invokes unpack.sh , I am not able to pass the packageName value from previous step to inline ansible.

---
  - hosts: "{{host_name}}"
    remote_user: "{{run_user}}"
    tasks:
      - name: Unpack the package
        shell: sh /home/yurtdxx67a/mig/unpack.sh "{{$packageName}}"  

任何想法都会对我有很大帮助.

Any idea will be great help for me.

2020 年 2 月 12 日

在我的情况下,要替换的变量在ansible-extra-param"内

In my case the variables to be substituted is within "ansible-extra-param"

  <command>
    <step-plugin type='com.batix.rundeck.plugins.AnsiblePlaybookInlineWorkflowStep'>
      <configuration>
        <entry key='ansible-become' value='false' />
        <entry key='ansible-disable-limit' value='false' />
        <entry key='ansible-extra-param' value='-i /tmp/workspace/CNRLS/hosts -e host_name=myhost -e run_user=${data.runUser} -e package_name=${data.packageName} --limit ${data.nodeIP} --ssh-extra-args=&apos;-o StrictHostKeyChecking=no&apos; ' />
        <entry key='ansible-playbook-inline' value='---&#10;  - hosts: "{{host_name}}"&#10;    remote_user: "{{run_user}}"&#10;    tasks:&#10;      - name: Check for connectivity&#10;        shell: sh /home/yurtdxx67a/mig/unpack.sh "{{package_name}}"  ' />
      </configuration>
    </step-plugin>
  </command>

我想使用这些变量.

run_user=${data.runUser} -e package_name=${data.packageName} --limit ${data.nodeIP}

run_user=${data.runUser} -e package_name=${data.packageName} --limit ${data.nodeIP}

这些变量是有价值的.当我显示echo ${data.packageName} ;echo ${data.runUser} ;回声 ${data.nodeIP} ;

these variable has value. when I display echo ${data.packageName} ; echo ${data.runUser} ; echo ${data.nodeIP} ;

我不确定如何将这些变量用作ansible-extra-param"参数的一部分

I am not sure how to use these variable as part of "ansible-extra-param' argument

再次感谢您

谢谢.德维加

推荐答案

您可以使用 数据传递 功能,您将其存储在数据变量中,然后使用 ${data.MYDATA} 格式将其发送到您的 ansible.

You can "extract" values from your script output using data passing feature, you'll store it on data variables and then send it to your ansible using ${data.MYDATA} format.

我留下一个非常基本的例子:

I leave a very basic example that works:

<joblist>
  <job>
    <defaultTab>nodes</defaultTab>
    <description></description>
    <dispatch>
      <excludePrecedence>true</excludePrecedence>
      <keepgoing>false</keepgoing>
      <rankOrder>ascending</rankOrder>
      <successOnEmptyNodeFilter>false</successOnEmptyNodeFilter>
      <threadcount>1</threadcount>
    </dispatch>
    <executionEnabled>true</executionEnabled>
    <id>c858b2a9-8328-4bdb-8955-0394b238cfbc</id>
    <loglevel>INFO</loglevel>
    <name>ExampleAnsible</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <nodefilters>
      <filter>192.168.33.2.*</filter>
    </nodefilters>
    <nodesSelectedByDefault>true</nodesSelectedByDefault>
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <plugins>
          <LogFilter type='key-value-data'>
            <config>
              <logData>true</logData>
              <regex>^(MYSTRING)\s*=\s*(.+)$</regex>
            </config>
          </LogFilter>
        </plugins>
        <script><![CDATA[# your script
echo "MYSTRING=World"]]></script>
        <scriptargs />
      </command>
      <command>
        <node-step-plugin type='com.batix.rundeck.plugins.AnsiblePlaybookInlineWorkflowNodeStep'>
          <configuration>
            <entry key='ansible-become' value='false' />
            <entry key='ansible-playbook-inline' value='---&#10;- name: hello-world&#10;  hosts: all&#10;  tasks:&#10;    - name: hello-world&#10;      copy:&#10;        content: hello ${data.MYSTRING}&#10;        dest: /home/vagrant/testfile.txt' />
            <entry key='ansible-ssh-passphrase-option' value='option.password' />
            <entry key='ansible-ssh-use-agent' value='false' />
          </configuration>
        </node-step-plugin>
      </command>
    </sequence>
    <uuid>c858b2a9-8328-4bdb-8955-0394b238cfbc</uuid>
  </job>
</joblist>

这篇关于从脚本步骤到内联 Ansible Playbook 的 Rundeck 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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