-1

I have a very long command with many arguments, and somehow it's not working the way it should work. The following knife command will connect to remote vCenter and create a VM called node1. How do I wrap the following command and run inside ruby? Am I doing something wrong?

var_name = 'node1'
var_folder = 'folder1'
var_datastore = 'datastore1'
var_template_file = 'template_foo'
var_template = 'foo'
var_location = 'US'

cmd = 'knife vsphere vm clone var_name --dest-folder var_folder --datastore var_datastore --template-file var_template_file --template var_template -f var_location'

system(cmd)
sawa
  • 165,429
  • 45
  • 277
  • 381
Satish
  • 16,544
  • 29
  • 93
  • 149

2 Answers2

2
require 'shellwords'
cmd = "knife vsphere vm clone #{var_name.shellescape} --dest-folder #{var_folder.shellescape} --datastore #{var_datastore.shellescape} --template-file #{var_template_file.shellescape} --template #{var_template.shellescape} -f #{var_location.shellescape}"

In your specific case it would work even without shellescape, but better safe than sorry.

Amadan
  • 191,408
  • 23
  • 240
  • 301
0

Variables are not resolved in your command. Try using #{var_name} etc for all variables in the varaible cmd