emyl / vagrant-triggers

Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.
MIT License
546 stars 35 forks source link

Issue using triggers to interact with the user #77

Closed debo closed 6 years ago

debo commented 7 years ago

I'm trying to leverage the provisioning feature of this plugin to collect the user input during provisioning but I am struggling in understanding how the visibility scope of ruby works in relation to the way the fire event is called.

Following is an example of what I am trying to do with some explainatory comment:

    aws_access_key, aws_access_secret = [nil] * 2  

    # this code is for clarification sake
    aws_access_key = 'foo'
    aws_access_secret = 'bar'
    print "#{aws_access_key}\n" # prints foo
    print "#{aws_access_secret}\n" # prints bar
    # =========================================

    config.vm.provision "trigger" do |t|

        # this code is for clarification sake
        print "#{aws_access_key}\n" # prints foo
        print "#{aws_access_secret}\n" # prints bar
        # =========================================

        t.fire do

            # this code is for clarification sake
            print "#{aws_access_key}\n" # prints foo
            print "#{aws_access_secret}\n" # prints bar
            # =========================================

            print "Please provide your AWS credentials\n"
            print "aws_access_key: "
            aws_access_key = STDIN.noecho(&:gets).chomp # say I type qwerty
            print "\naws_access_secret: "
            aws_access_secret = STDIN.noecho(&:gets).chomp  # say I type ytrewq
            print "\n"

            # this code is for clarification sake
            print "#{aws_access_key}\n" # prints qwerty
            print "#{aws_access_secret}\n" # prints ytrewq          
            # =========================================
        end
    end

    config.vm.provision "shell" do |s|
        s.inline = "echo Key: $1 Secret: $2" # echos foo and bar
        s.args = ["#{$aws_access_key}", "#{$aws_access_secret}"]
    end

As you might understand what I am expecting is to have the user input being available also to the second provisioner. How can I achieve that?

walterdolce commented 7 years ago

+1 to the questio above. I am trying to achieve the same thing and I'm getting the same behaviour. Are we missing something?