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

问题描述

我需要从Web URL下载文件并膨胀到没有Internet访问权限的远程服务器中.

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/

现在第二步

我正在运行ins 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}

这些变量具有价值.当我展示回声$ {data.packageName};回声$ {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变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 09:04