From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/vagrant/provisioning%2Fshell.html | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 devdocs/vagrant/provisioning%2Fshell.html (limited to 'devdocs/vagrant/provisioning%2Fshell.html') diff --git a/devdocs/vagrant/provisioning%2Fshell.html b/devdocs/vagrant/provisioning%2Fshell.html new file mode 100644 index 00000000..0b8112e5 --- /dev/null +++ b/devdocs/vagrant/provisioning%2Fshell.html @@ -0,0 +1,60 @@ +

Shell Provisioner

Provisioner name: "shell"

The Vagrant Shell provisioner allows you to upload and execute a script within the guest machine.

Shell provisioning is ideal for users new to Vagrant who want to get up and running quickly and provides a strong alternative for users who are not comfortable with a full configuration management system such as Chef or Puppet.

For POSIX-like machines, the shell provisioner executes scripts with SSH. For Windows guest machines that are configured to use WinRM, the shell provisioner executes PowerShell and Batch scripts over WinRM.

Options

The shell provisioner takes various options. One of inline or path is required:

The remainder of the available options are optional:

Inline Scripts

Perhaps the easiest way to get started is with an inline script. An inline script is a script that is given to Vagrant directly within the Vagrantfile. An example is best:

Vagrant.configure("2") do |config|
+  config.vm.provision "shell",
+    inline: "echo Hello, World"
+end
+
+

This causes echo Hello, World to be run within the guest machine when provisioners are run.

Combined with a little bit more Ruby, this makes it very easy to embed your shell scripts directly within your Vagrantfile. Another example below:

$script = <<-SCRIPT
+echo I am provisioning...
+date > /etc/vagrant_provisioned_at
+SCRIPT
+
+Vagrant.configure("2") do |config|
+  config.vm.provision "shell", inline: $script
+end
+
+

I understand that if you are not familiar with Ruby, the above may seem very advanced or foreign. But do not fear, what it is doing is quite simple: the script is assigned to a global variable $script. This global variable contains a string which is then passed in as the inline script to the Vagrant configuration.

Of course, if any Ruby in your Vagrantfile outside of basic variable assignment makes you uncomfortable, you can use an actual script file, documented in the next section.

For Windows guest machines, the inline script must be PowerShell. Batch scripts are not allowed as inline scripts.

External Script

The shell provisioner can also take an option specifying a path to a shell script on the host machine. Vagrant will then upload this script into the guest and execute it. An example:

Vagrant.configure("2") do |config|
+  config.vm.provision "shell", path: "script.sh"
+end
+
+

Relative paths, such as above, are expanded relative to the location of the root Vagrantfile for your project. Absolute paths can also be used, as well as shortcuts such as ~ (home directory) and .. (parent directory).

If you use a remote script as part of your provisioning process, you can pass in its URL as the path argument as well:

Vagrant.configure("2") do |config|
+  config.vm.provision "shell", path: "https://example.com/provisioner.sh"
+end
+
+

If you are running a Batch or PowerShell script for Windows, make sure that the external path has the proper extension (".bat" or ".ps1"), because Windows uses this to determine what kind of file it is to execute. If you exclude this extension, it likely will not work.

To run a script already available on the guest you can use an inline script to invoke the remote script on the guest.

Vagrant.configure("2") do |config|
+  config.vm.provision "shell",
+    inline: "/bin/sh /path/to/the/script/already/on/the/guest.sh"
+end
+
+

Script Arguments

You can parameterize your scripts as well like any normal shell script. These arguments can be specified to the shell provisioner. They should be specified as a string as they'd be typed on the command line, so be sure to properly escape anything:

Vagrant.configure("2") do |config|
+  config.vm.provision "shell" do |s|
+    s.inline = "echo $1"
+    s.args   = "'hello, world!'"
+  end
+end
+
+

You can also specify arguments as an array if you do not want to worry about quoting:

Vagrant.configure("2") do |config|
+  config.vm.provision "shell" do |s|
+    s.inline = "echo $1"
+    s.args   = ["hello, world!"]
+  end
+end
+
+

+ © 2010–2018 Mitchell Hashimoto
Licensed under the MPL 2.0 License.
+ https://www.vagrantup.com/docs/provisioning/shell.html +

+
-- cgit v1.2.3