2

I want to be able to set a variable in a shell-script - which is part of a multi-part cloud-init userdata configuration setup, and use this variable in a cloud-config script that comes later in the multi-part userdata.

Is this possible to do? An example would be helpful.

donatello
  • 5,727
  • 6
  • 32
  • 56

1 Answers1

2

You could just use a file. Set the "variable" with echo "value" > /tmp/myvar and get it with echo `cat /tmp/myvar`.

whereswalden
  • 4,819
  • 3
  • 27
  • 41
  • A cloud config script cannot run echo to fetch a variable like this, right? – donatello May 01 '14 at 21:46
  • The echo in this case is just an example of a command using that variable. A more accurate example might be a variable named "doTheThing". You could set the value with `echo "true" > /tmp/doTheThing` and test for it using ``if `cat /tmp/doTheThing`; then do a thing; fi`` – whereswalden May 02 '14 at 17:09
  • It doesn't support variables, but is a great workaround! – Dean Meehan Sep 22 '15 at 08:41