95 Commits

Author SHA1 Message Date
Chris Roberts
e7a6f397da Updates for Ruby 3.0 2021-06-21 15:57:46 -07:00
sophia
fb2470f48d Ensure shell provisioner gets extension specified in path config if exists 2020-05-26 16:35:31 -04:00
Jeff Bonhag
2c4a40fccb
Fix issues with shell provisioner when WinSSH shell is set to cmd (#11547)
This commit fixes a couple of issues with the shell provisioner when the
WinSSH shell is set to cmd:

- A check for the .bat extension returned by File.extname
- Execute inline scripts with PowerShell when upload_path ends with .ps1

* Ensure script has correct extension

Co-Authored-By: Sophia Castellarin <sophia@hashicorp.com>
2020-04-24 15:56:27 -04:00
sophia
4d516e2cae Test provision_winssh 2020-04-17 13:11:57 -04:00
sophia
2ddd12047c Ensure windows files get an extension 2020-04-17 10:31:24 -04:00
Chris Roberts
852c549886 Force powershell on connection for consistent behavior
This patches the connection instances generated for the winssh
communicator so when a command is executed it is always run
with powershell. This prevents inconsistencies with argument
handling based on what the default shell is set to on the remote
side.

Since powershell is the default, environment variable template
only needs to be set for powershell style. If the shell setting
is updated to `cmd`, the command will be properly prefixed.

Default shell has been updated to powershell, to prevent extraneous
wrapping where it's not required. The `#ready?` check has also been
updated to use a constant value, which is overridden within winssh
as a blank command is invalid.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
9a26c123b9 Use SFTP for Windows file transfer
SFTP is more reliable than SCP when dealing with unknown sshd
configurations on the server side. It also provides a convenient
facility for creating remote directories, so we can remove the
Windows-specific `#create_remote_directory` method.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
b2aa16dc78 Set remote script extension from local script extension 2020-03-04 15:08:03 -08:00
Jeff Bonhag
85f0fce57a Allow #provision_winrm to modify upload_path
We need to ensure that Windows files have an extension when provisioning
via WinRM.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
4b7d55afaa Fixup paths to work with server-side Bash
This commit normalizes our Windows paths to use `/` instead of `\`.
These paths are compatible with both cmd and PowerShell, and are
required if the server-side shell is set to Bash.

The OpenSSH server executes all commands inside a default login shell
which cannot be controlled by the Vagrant configuration. So what ends up
getting executed on the server side looks something like this:

    "c:\\program files\\git\\bin\\bash.exe" -c "C:\\Windows\\Temp\\vagrant-ssh20200130-41670-1w5nsjy.bat"

By flipping the direction of the directory slashes, we end up with:

    "c:\\program files\\git\\bin\\bash.exe" -c "C:/Windows/Temp/vagrant-ssh20200130-43415-f1d5n2.bat"

This works whether the server-side shell is set to cmd, powershell, or
bash.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
8affdd24b6 Wire up inline command for popular Windows shells
* Remove connection between shell provisioner directory config and WinSSH
directory config because these should remain separate.
2020-03-04 15:08:03 -08:00
Jeff Bonhag
df7c11a3a7 Fix issues with Windows SSH provisioner
Windows commands that run over SSH are wrapped in a script that writes a
special marker to the two output streams (stdout and stderr).  This
allows Vagrant to consume the output streams.

Unfortunately, this leads to a sort of chicken-and-egg problem where no
commands can be run before a wrapper script exists. For example, you
can't make a destination directory to upload the wrapper script without
first creating a wrapper script to make the directory. :)

This commit changes the behavior of the WinSSH communicator to assume
that the destination directory already exists for provisioning scripts.

It also moves the default `upload_path` from the shell provisioner
config so we can have OS-specific defaults.

Finally, it introduces a Windows-specific #upload method which will
properly use a Windows path separator on a non-Windows host.
2020-03-04 15:08:03 -08:00
Chris Roberts
7fb81bcea1 Add support for other checksum types 2019-10-08 11:23:48 -07:00
Chris Roberts
e735453422 Add reboot option to shell provisioner
Adds a `reboot` option which allows the guest to be rebooted after
the completion of a shell provisioning task. The guest must support
the `:reboot` capability. Like the `reset` option, the `reboot`
option may be provided without defining `inline` or `file` options
when a reboot may be required between other provisioners.

Fixes #8639
2018-12-21 15:50:59 -08:00
Chris Roberts
29880ccd1f Add option to shell provisioner to reset communicator 2018-11-12 15:36:21 -08:00
Chris Roberts
3664f1a627 Allow hiding environment variable values in shell provisioner 2018-01-12 17:33:47 -08:00
Vít Ondruch
7187e6f909 Use Integer instead of Fixnum for Ruby 2.4+ compatibility. 2017-10-23 10:57:36 -07:00
Mikhail Bulash
508d94d466 provisioners/shell: Use ui.detail for displaying output
Output format of ui.info method (bold text) makes reading long script outputs really heavy on the eyes. ui.detail is a better match for this type of output.
2017-09-18 17:55:07 +03:00
Brian Cain
01528689fd (#8716) Dup string if frozen for line endings
Prior to this commit, if a user passed in a script that was frozen,
the shell provisioner would fail to modify the script to replace line
endings for windows because the string was immutable. This commit fixes
that by dup'ing the string so that it can have its line endings replaced
2017-08-15 08:38:30 -07:00
Chris Roberts
71bfe7c884 Fix shell provisioner to execute batch files correctly
Call cmd.exe explicitly when running batch files to easily
manage special characters that may be within the path.

Fixes #8535
2017-04-28 15:05:08 -07:00
Chris Roberts
0e89fdf182 Merge pull request #8498 from chrisroberts/win/spaces
Quote exec_path to properly handle spaces in path
2017-04-20 16:08:24 -07:00
Chris Roberts
c963532d6e Use configured upload path for winssh communicator 2017-04-20 16:05:41 -07:00
Chris Roberts
82e268a3e2 Quote exec_path to properly handle spaces in path
Fixes #7234
2017-04-19 12:23:55 -07:00
Chris Roberts
c56acfab94 Add WinSSH communicator 2017-04-15 07:12:58 -07:00
Chris Roberts
da45ca707c Add md5 and sha1 checksum support to Downloader.
Allows checksum validation on downloaded files via Util::Downloader
using MD5 and/or SHA1 checksums. This also integrates checksum validation
support with the shell provisioner for downloaded remote files.
2016-11-09 16:05:39 -08:00
Seth Vargo
9de5126143 Convert env values to strings before escaping 2015-12-22 14:23:56 -05:00
Seth Vargo
930e166b47 Add :env option to shell provisioner 2015-11-23 19:29:35 -05:00
Mitchell Hashimoto
e6098f6c4f rename to powershell_elevated_interactive 2015-11-18 12:51:18 -08:00
Mitchell Hashimoto
dde21bc95a fix file permissions 2015-11-18 12:48:41 -08:00
Dan Dunckel
9d87be51da Small refactor on conditional check and add tests 2015-10-15 12:25:50 -07:00
Marc Siegfriedt
8e87990599 add the option to make elevated interactive scripts 2015-10-15 12:25:50 -07:00
Sam Phippen
53714abfa3 Handle encoding errors in shell provisioner newline normalization.
The problem demonstrated in #6065 is that a string has incorrectly been
encoded with US-ASCII even though it contains invalid US-ASCII byte
sequences (any byte with the most significant bit on is invalid in the
US-ASCII encoding).

The thing about doing newline normalization is that it is not actually
sensitive to the presence of US-ASCII byte sequenzes. Additionally, it
is very unlikely that a user will ever be using an encoding where \r\n
is not encoded the same as it would be in ASCII.

This patch first tries the existing method of normalizing the newlines
in the provided script file, if that fails for any reason it force
encodes the string to ASCII-8BIT (which allows the most significant bit
to be on in any individual byte) and then performs the substitution in
that byte space.
2015-09-12 14:36:54 +01:00
Seth Vargo
50c0c487fb Style cleanup for new name option 2015-05-30 20:57:49 -07:00
James Shubin
b16b85aa7d Add :name attribute to shell provisioner.
This allows the display of friendly output to the user when we think an
important action should be labeled a certain way. This makes vagrant
output a lot more useful when many inline shell provisioners are
present.
2015-04-18 00:35:21 -04:00
Mitchell Hashimoto
da91741b7c provisioners/shell: fix typo 2014-10-23 22:49:26 -07:00
Mitchell Hashimoto
a7d3458abc provisioners/shell: retry getting SSH info a few times [GH-3924] 2014-10-23 22:48:48 -07:00
Mitchell Hashimoto
3f01a99148 provisioners/shell: rename shell_args to powershell-args 2014-10-23 09:53:14 -07:00
Eris Belew
7a73f5bd7c Update shell provisioner for powershell to add "shell_args", saner defaults and more useful detail in logging output; Add Eclipse .project file to .gitignore IDE section 2014-09-23 12:46:25 -07:00
Mitchell Hashimoto
e82d425719 Merge pull request #4087 from zr40/fix/master/prevent-double-output
Don't output stdout and stderr twice when shell provisioner fails
2014-08-06 10:32:13 -07:00
Ben Dean
dbb92ae412 change the shell provision config to make all the args strings
specifically arrays could contain `Fixnum` args and those wouldn't get turned into strings.
2014-07-22 15:41:01 -04:00
Matthijs van der Vleuten
1091b4cb54 Don't output stdout and stderr twice when shell provisioner fails
[GH-4086]
2014-06-23 11:35:40 +02:00
Kalman Hazins
bb052366f7 Change symbols inside hashes to 1.9 JSON-like syntax 2014-05-22 12:35:12 -04:00
Fabio Rehm
1eec62cb9e provisioners/shell: Fix shell provisioning when config.binary is set to false [GH-3712]
The `config` in use was the Shell provisioner config that does not expose
access to the VM configs.

References https://github.com/fgrehm/vagrant-lxc/issues/284
2014-05-08 18:55:07 -03:00
Shawn Neal
cc905d7923 Fix remote/downloaded shell scripts
The temporary shell script that we downloaded the script too was being deleted twice, thus causing an error on the secondary delete.
2014-04-30 19:39:37 -07:00
Shawn Neal
392269a8eb Default the WinRM shell provisioner to privileged (elevated) 2014-04-30 19:35:02 -07:00
Mitchell Hashimoto
1c7faae1ee provisioners/*: prefix the output 2014-04-21 13:56:19 -07:00
Mitchell Hashimoto
bec2cbbf4d provisioners/shell: check for winrm should be on machine config 2014-04-21 13:53:56 -07:00
Mitchell Hashimoto
4145aa6bcd privisioners/shell: wait for reboot if we can 2014-04-21 13:53:54 -07:00
Mitchell Hashimoto
4fc6fbeef6 privisioners/shell: fix syntax error 2014-04-21 13:53:53 -07:00
Mitchell Hashimoto
286fd2f2f8 provisioners/shell: friendly output if winrm shell provisioning 2014-04-21 13:53:52 -07:00