Provisioning is used to automatically configure a virtual machine. It is performed automatically when a virtual machine is first created (using vagrant up
). It can also be re-run later using vagrant provision
.
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision "ansible" do |ansible|
ansible.playbook = "vagrant-playbook.yml"
end
end
vagrant-playbook.yml
---
- hosts: default
tasks:
- name: Say hello
debug:
msg: 'Hello, World'
vagrant up
By default the box will be provisioned.
vagrant up --no-provision
vagrant provision
The shell provisioner runs a shell script when provisioning.
$setup = <<SETUP
# You can write your shell script between here ...
sudo echo "Hello, World!" > /etc/motd.tail
# ... and here.
SETUP
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision "shell", inline: $setup
end
# provision/bootstrap-controller.sh : path and shell filename from vagrantfile location
config.vm.define "configcontroller" do |controller|
...
controller.vm.provision :shell do |shell|
shell.path = "provision/bootstrap-controller.sh"
end
...
Parameter | Details |
---|---|
COMMANDS | The shell commands to run. Can be a string (e.g. "echo \"Hello, World!\"" ) or a string variable (e.g. $setup ). |