How can I define a node specific constant BASE_DIRECTORY, that I can use within my scripts.
For example:
And within my scripts, I want to resolve $BASE_DIRECTORY to do actions on that directory
You can define any custom attribute in your model source like base-directory=/some/value
, e.g:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<node name="node00" description="Node 00" tags="db" hostname="192.168.56.20" osArch="amd64" osFamily="unix" osName="Linux" osVersion="3.10.0-1062.4.1.el7.x86_64" username="vagrant" ssh-key-storage-path="keys/rundeck" base-directory="/home/vagrant/myapp1" />
<node name="node01" description="Node 01" tags="db" hostname="192.168.56.21" osArch="amd64" osFamily="unix" osName="Linux" osVersion="3.10.0-1062.4.1.el7.x86_64" username="vagrant" ssh-key-storage-path="keys/rundeck" base-directory="/home/vagrant/myapp2" />
<node name="node02" description="Node 02" tags="bk" hostname="192.168.56.22" osArch="amd64" osFamily="unix" osName="Linux" osVersion="3.10.0-1062.4.1.el7.x86_64" username="vagrant" ssh-key-storage-path="keys/rundeck" base-directory="/home/vagrant/myapp3" />
</project>
Now call the ${node.base-directory}
env var (@node.base-directory@
on inline-scripts or $RD_NODE_BASE-DIRECTORY
for "external scripts").
Tested using this job definition:
- defaultTab: nodes
description: ''
executionEnabled: true
id: c16356aa-b4c1-465e-9ac0-0bd89aa8bc30
loglevel: INFO
name: TestRemoteJob
nodeFilterEditable: false
nodefilters:
dispatch:
excludePrecedence: true
keepgoing: false
rankOrder: ascending
successOnEmptyNodeFilter: false
threadcount: '1'
filter: .*
nodesSelectedByDefault: true
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- script: echo @node.base-directory@
keepgoing: false
strategy: node-first
uuid: c16356aa-b4c1-465e-9ac0-0bd89aa8bc30
Check the result.
To use RD_*
vars on remote SSH nodes, please take a look at this.