StackScript UDF variables

Linode Staff

I'm trying to write the value of a UDF variable in my StackScript to a file using the code:

echo ${udf_variable} >> file.txt

but the file remains empty after deploying a Linode with the StackScript. The API call which defines the UDF variable looks like this:

"stackscript_data": { "udf_variable":"value" }

2 Replies

When using a UDF variable in a StackScript, it seems that it is allowed to declare it without regard to capitalization, but subsequent references must be made in all caps. You must also pass it into the script with correct capitalization. While I do not have documentation to point to for this, it is a behavior that I have found to be consistent in my scripts, and the behavior remains the same whether I'm scripting in Bash or Python (I haven't tried other languages). That said, to answer the question directly - the API call looks good, but the line in your script should read:

echo "${UDF_VARIABLE}"

I wanted to add a quick piece here about using StackScripts with the Linode-CLI. When passing data to a StackScript from the CLI, it is necessary to put the entire JSON string for stackscript_data in 'single quotes'. Consider the following Bash script snippet, which builds a Linode from a StackScript:

#!/bin/bash

label="ss_test"
region="us-east"
password="s3cur3_passw0rD"
image="linode/ubuntu16.04lts"
plan="g6-nanode-1"

linode-cli linodes create --label "${label}" \
                          --region "${region}" \
                          --root_pass "${password}" \
                          --stackscript_id <stackscript_id_number> \
                          --stackscript_data '{ "udf_variable":"value" }' \
                          --image "${image}" \
                          --type "${plan}"

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct