

The test.sh script should run when the name given to -provision-with matches the name in the Vagrantfile. provision-with x,y,z Enable only certain provisioners, by type or by name. $ # Confirm that the help text shows that -provision-with takes either type or name as an argument $ vagrant provision -provision-with "shell" These also include some examples from the " Vagrant - Getting Started" article, and the repository is under active maintenance.$ vagrant provision -provision-with "test.sh" I have uploaded a bunch of examples, which you can use to build your own provisioners. You can curl this IP address to if it worked. # Start the instanceįedora: Running: /tmp/vagrant-shell20210525-15681-ujjacd.sh In addition, it will output the IP addresses assigned to it with the command echo "$(hostname -I)" at the end.
#VAGRANT PROVISION INSTALL#
Starting the instance will apply the script and therefore install httpd and start the service. Let's also create the script with the below content. Below, I will show how you can write a small script to install and enable the Apache httpd server in a Fedora instance.įirst, you need to create a Vagrantfile like this. You just need to create your script file and add it to your Vagrantfile for provisioning. If you want to prepare more complex setups, you should have a look at prepared scripts. Vagrant will take care of the shell command and the reboot, and you will end up with an updated and rebooted deployment.
#VAGRANT PROVISION UPDATE#
If you may know, it is a good idea to reboot a machine after an update and the shell provisioner has some options to take care of this. We will end up with an updated instance, that is updated. => fedora: Running provisioner: shell.įedora: = Starting the machine will also trigger the shell command and therefore update the system. We just need to create a Vagrantfile with the below content. This behavior can be tuned with the privileges (boolean) option. This is very useful, if you want to update your instance on creation or trigger something inside the machine.īe aware, that the shell provisioner is always used with privileges (sudo for Linux based OS). Inline shell commands can be very useful, if you just want to trigger a single command. You can differentiate in two general approaches: "Inline shell commands" and "prepared scripts".

This is especially useful, if you don't have any experience with Chef, Puppet or Ansible. This allows to execute single commands and shell scripts during the creation and afterwards. In case you need something more, like running a script during the creation, you can check out the Shell provisioner. You can also check out the above example in this repository. You can use this feature to copy scripts, configuration files and binaries to your instance, so it can be used there. If you connect to the machine, you can verify, that the file is in its place. If you changed something, you can also trigger the provision step manually. You can start the Vagrant instance now, which will also trigger the provision step during the creation. In this case, we want to copy a file "nf" to the home directory of the SSH user. You can see, there is a new # provision section introduced. First, you have to create a Vagrantfile as seen below. Be aware, that you can only copy files to a location, where this user has permissions to create files. You can determine the user by running the command vagrant ssh-config. It works by simply copying a file via SCP/SSH as the SSH user to the Vagrant machine. The first and most simple provisioner is a simple file upload. The guide is tested on Fedora 34 with Vagrant 2.2.16. Let's see how provisioners work with some simple examples. Please have a look at the documentation for all the details. Vagrant provisioners can be tuned and tweaked to your liking with lots of options. Since everything is on your local machine, there is no need to push something to a test or production system, but test your scripts, playbooks and chef containers locally. In addition, you can use these provisioners also to test the functionality of these tools. This can be very useful to prepare a complete environment with different tools installed and configurations applied. You can copy files, apply scripts, create containers or run Ansible playbooks. Vagrant can do provisioning on each creation ( vagrant up) automatically or manually ( vagrant provision). If you haven't heard of Vagrant, please have a look at the " Vagrant - Getting Started" article. In this article, I will tackle file and shell provisioners.
#VAGRANT PROVISION SOFTWARE#
Very often you will need to add more software to these VMs or test your new web project. Vagrant is a powerful tool, that can help to create and manage VMs on different operating systems.
