Onetemplate context parameter format [solved]


I’m having a extremely hard time trying to pass in additional context when creating testing VMs.
So, first, the onetemplate --help output says you can use this to add context variables.
After a few hours I figured it doesn’t add, but overwrite the context.
So the VM’s network context was lost, for example.
All examples seem to just show how to add a single item, which would be enough if it didn’t overwrite it. So now I am trying to add three.

I tried like this:
onetemplate instantiate 52 --name=test-c7 --context="\[NETWORK="YES",SSH_PUBLIC_KEY="\$USER[SSH_PUBLIC_KEY]",${1}\]" 2>&1

$1 is “SET_HOSTNAME=“myhost.domain.tld”” for example

I have tried many variations of escaping, and after 20 or 30 tries, I give up now.
The example below has less quotes. I also had tries with more. Until I know what it really wants it’s hopeless to get it right.

See for yourself:

+ for c in '"SET_HOSTNAME=myhost.domain.tld"' '"DNS_HOSTNAME=yes"'
++ launch SET_HOSTNAME=myhost.domain.tld
++ onetemplate instantiate 52 --name=test-c7 '--context=\[NETWORK=YES,SSH_PUBLIC_KEY=$USER[SSH_PUBLIC_KEY],SET_HOSTNAME=myhost.domain.tld\]'
++ return 255
+ LAUNCHCODE='Parse error: syntax error, unexpected VARIABLE, expecting COMMA or CBRACKET at line 4, columns 66:80'
+ '[' 255 '!=' 0 ']'
  1. why does it nuke the context instead of adding?
  2. how does one pass more than one context line, especially with ONE variables like $USER?

Hi Florian,

I just tried nearly the same today (while trying to inject the public and private keys for the salt minion).

From my basic understanding of the ruby code in one_helper.rb (around lines 983-1046) I think that the context is regenerated completely.
The function also incorporates the variables --net_context and --ssh (file instead of the user variable) into the CONTEXT.
So I assume that the right syntax should be something like this:

onetemplate instantiate 52 --name jenkins-slave --net_context --ssh /srv/ssh-pub-keys/ --context SET_HOSTNAME=jenkins_slave2,PUB_KEY=HERE,PRIV_KEY=THERE

hope this helps

Bernhard J. M. Grün

I just got some help by Javier.

19:41 < jfontan> darkfader, the help text is not right, is used for both template creation and
instantiation and is not right for instantiation
19:41 < jfontan> darkfader, you can do it this way:
19:41 < jfontan> --context
19:42 < jfontan> the error is the quotes in the SSH key

20:16 < jfontan> for that kind of changes in the context part I usually add a new template variable
20:16 < jfontan> in your case I can set in context of the template SET_HOSTNAME="$MY_HOSTNAME"
20:17 < jfontan> and on instantiation I add --raw 'MY_HOSTNAME=“myhost.domain.tld”'
20:17 < jfontan> that way you don’t need to rewrite the whole context section
20:20 < darkfader> oh, nice yes that would work
20:20 < darkfader> doing a lot more tests over next days so you just saved me hours :wink:

I’ve tested using a external var and --raw - this way it works.


1 Like