vagrant provision: read line from keyboard/stdin

2019-09-06 02:01发布

问题:

And so, I have a Vagrantfile with code:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
...
  config.vm.provision "shell", inline: 'echo "Read line:" && read t && echo "$t"'
...
end

and when I execute vagrant provision i have that output:

$ vagrant provision
...
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Read line:
==> default: exit

that is no suggest enter a line from keyboard/stdin!

What I should do for reading line from keyboard/stdin during provision shell script execution?

回答1:

I do it this way, in my Vagrantfile

puts "Input text: "
input = STDIN.gets.chomp

config.vm.provision :shell, inline: "echo #{input}"