Ansible has switched dependency between version 3.4.0 (ansible-base) and 4.0.0 (ansible-core), which now outputs new version scheme of "ansible [core 2.11.0]" instead of "ansible 2.10.9".
This fix keeps old and new version detection working.
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>
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.
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.
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.
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.