Search code examples
vagrantvagrantfilevagrant-provision

vagrant provision: read line from keyboard/stdin


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?


Solution

  • I do it this way, in my Vagrantfile

    puts "Input text: "
    input = STDIN.gets.chomp
    
    config.vm.provision :shell, inline: "echo #{input}"