16

I have a shell provisioning script that invokes a command that requires user input - but when I run vagrant provision, the process hangs at that point in the script, as the command is waiting for my input, but there is nowhere to give it. Is there any way around this - i.e. to force the script to run in some interactive mode?

The specifics are that I creating a clean Ubuntu VM, and then invoking the Heroku CLI to download a database backup (this is in my provisioning script):

curl -o /tmp/db.backup `heroku pgbackups:url -a myapp`

However, because this is a clean VM, and therefore this is the first time that I have run an Heroku CLI command, I am prompted for my login credentials. Because the script is being managed by Vagrant, there is no interactive shell attached, and so the script just hangs there.

Hugo Rodger-Brown
  • 11,054
  • 11
  • 52
  • 78

2 Answers2

4

If you want to pass temporary input or variables to a Vagrant script, you can have them enter their credentials as temporary environment variables for that command by placing them first on the same line:

username=x password=x vagrant provision

and access them from within Vagrantfile as

$u = ENV['username']
$p = ENV['password']

Then you can pass them as an argument to your bash script:

config.vm.provision "shell" do |s|
    s.inline: "echo username: $1, password: $2"
    s.args: [$u, $p]
end

You can install something like expect in the vm to handle passing those variables to the curl command.

Richard
  • 333
  • 3
  • 7
2

I'm assuming you don't want to hard code your credentials in plain text thus trying to force an interactive mode. Thing is just as you I don't see such option in vagrant provision doc ( http://docs.vagrantup.com/v1/docs/provisioners/shell.html ) so one way or another you need to embed the authentication within your script. Have you thought about using something like getting a token and use the heroku REST Api instead of the CLI? https://devcenter.heroku.com/articles/authentication

Jaime Gago
  • 342
  • 1
  • 4
  • 9
  • 2
    You're right - I'm building a generic box for a group of developers, all of whom need to supply their own credentials. I've worked around the problem for now. – Hugo Rodger-Brown Jan 31 '13 at 16:04
  • @JoeBlock you can work around it by using a config file that users enter data in pre-emptively, and expect: http://linux.die.net/man/1/expect – SgtPooki Jul 23 '14 at 15:57