Pass command line argument to vagrant shell script provisioner

前端 未结 2 1597
无人共我
无人共我 2021-01-14 10:25

Similar to this question: Passing variable to a shell script provisioner in vagrant

I want to pass variables to a shell script provisioner but I want to set these va

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 11:25

    In your Vagrantfile, add the following -

    {
        "PROVISION_PARAMS" => "some_default_values",
    }.each { |key, value| ENV[key] = value if ENV[key] == nil }
      
    

    These arguments can now be passed to shell script provisioner in the following way -

    config.vm.provision :shell, privileged: true, run: "always",
                                :path => "../../scripts/script.ps1", 
                                :args => ENV['PROVISION_PARAMS']
    

    You can now provide command line arguments to this script in the following manner -

    $ PROVISION_PARAMS=' param1 param2 "param 3" ' vagrant provision
    

    And the script will take default values if these parameters are not specified.

提交回复
热议问题