user2439278
user2439278

Reputation: 1214

Running script automatically in vagrant

How can I run a script automatically when vagrant is up? I used provision method. But in that method i need to point out some .sh file. I dont want to point to .sh file. I need to build the script within the Vagrantfile. Please help me to fix this issue.

I tried

Vagrant::Config.run do |config|
  config.vm.provision :shell, :path => "test.sh
end 

I want to append the scripts in test.sh into vagrant file directly.

Upvotes: 1

Views: 5795

Answers (1)

Terry Wang
Terry Wang

Reputation: 13920

You can use inline script in Vagrantfile, even Here Document which made complex shell scripts embedded in it possible.

Example:

$script = <<'EOF'
echo shell provisioning...
date -R > /etc/vagrant_provisioned_at
EOF

Vagrant.configure("2") do |config|
  config.vm.provision :shell, :inline => $script
end

NOTE: single quoted LimitString is to escape special characters like or$`.

Check the Docs out => http://docs.vagrantup.com/v2/provisioning/shell.html

Upvotes: 3

Related Questions