Rundeck variable from script steps to Inline Ansible Playbook

五迷三道 提交于 2021-01-29 00:00:34

问题


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

  1. Rundeck downloads the file into local path wget, then push the file to destination server using SSH
  2. Rundeck to execute script on remote node to inflate the file copied using above step and perform other housekeeping activity, (its a bash shell script)

I am with very little knowledge on using 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/

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

Now Step Two

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.

Edit:12-Feb-2020

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>

I want to use these varaiables.

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

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

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

Thank you again

Thank you. Dwija


回答1:


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>


来源:https://stackoverflow.com/questions/59750386/rundeck-variable-from-script-steps-to-inline-ansible-playbook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!