returning a value from a provision script to vagrant

前端 未结 2 1570
抹茶落季
抹茶落季 2020-12-19 06:33

Is it possible to return a value from a provision script back to vagrant?

response = config.vm.provision( \"shell\", path: \"script.sh\" )

if response = \'o         


        
2条回答
  •  攒了一身酷
    2020-12-19 06:45

    I was able to get it from the VMs by doing this way:

    On Windows:

    config.trigger.after :provision do |trigger|
        trigger.name = "create token"
        trigger.run = {"inline": "vagrant ssh --no-tty -c 'hostname' master01 > test.txt"}
    end
    

    On Mac:

    config.trigger.after :provision do |trigger|
      trigger.name = "create token"
      trigger.run = {"inline": "/bin/bash -c 'vagrant ssh --no-tty -c "hostname" master01 > test.txt'"}
    end
    

    This will dump the output of the command from the VM to the given file in CWD on the host.

    Notes:

    • About bash redirection - why '/bin/bash -c' is required? (here in case of Mac) - https://github.com/hashicorp/vagrant/issues/10674
    • I am using Vagrant 2.2.6

提交回复
热议问题