Vagrant unable to mount SMB after upgrade to 1.7.4 - vagrant

I'm using vagrant on windows 8, with the hyper-v provider starting a windows server 2012 box.
Before I updated to vagrant 1.7.4 I was on version 1.7.2, and everything worked.
But after updating I am getting an error when it is trying to mount the shared folder:
The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
cmdkey /add:xxx.xxx.xxx.xxx /user:DOMAIN\user /pass:Password
Stdout from the command:
Stderr from the command:
Exception calling "RegisterTaskDefinition" with "7" argument(s): "The user
name or password is incorrect. (Exception from HRESULT: 0x8007052E)"
At C:\tmp\vagrant-elevated-shell.ps1:58 char:1
+ $folder.RegisterTaskDefinition($task_name, $task, 6, $username, $password,
1, $n ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
I have replaced the details from the line:
cmdkey /add:xxx.xxx.xxx.xxx /user:DOMAIN\user /pass:Password
With placeholders for obvious reasons. I did try and run the command above in the VM and I get the following output:
CMDKEY: Credential added successfully.
So I assume it is working correctly. Has something changed or broken in 1.7.4?

I have figured out a fix for this.
Our password contained dollar signs ($), these were being stripped out in the vagrant-elevated-shell.ps1 script.
I have forked the vagrant repo and made the change and made a pull request - https://github.com/mitchellh/vagrant/pull/6452
To patch your local environment, you can find the communicator.rb file on your local machine at:
C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.4\plugins\communicators\winrm\communicator.rb
(provided you used the default setting in the installer)

Related

Ansible (2.11 +) error with winrm when path invalid in environment variable (win_stat task)

we have an Ansible script to deploy software on Windows. One of the task if to check the existence of a folder with win_stat command.
However, om some servers, the task throws an error when a path that doesn't exist is defined in the 'LIB' environment variable on the windows server (the path has nothing to do with what we check)
I'm able to reproduce with a dead simple script:
- hosts: all
gather_facts: no
tasks:
- name: Check addon folder
win_stat:
path: 'C:\temp\'
and the error is (with verbose):
The full traceback is:
(0) : Warning as Error: Invalid search path 'System.Collections.DictionaryEntry' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '
(1) : using Microsoft.Win32.SafeHandles;
At line:408 char:5
+ Add-Type -TypeDefinition $link_util
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
ScriptStackTrace:
at Load-LinkUtils, <No file>: line 408
at <ScriptBlock>, <No file>: line 76
fatal: [IADCMP019]: FAILED! => {
"changed": false,
"msg": "Unhandled exception while executing module: (0) : Warning as Error: Invalid search path 'System.Collections.DictionaryEntry' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '\n\n(1) : using Microsoft.Win32.SafeHandles;\n"
}
Problems happens with 2.11.6 and 2.11.4 of Ansible core, but not with 2.10 (at least 2.10.9)
I'm wondering if it's a new check in 2.11 or if it's something I should open a bug report about.
EDIT1: changed 'c:' to 'c:\temp' as the win_stat command is long on the former, much faster on the later
I wasn't looking in the right repository for this. The bug is already opened, on ansible.windows collection : https://github.com/ansible-collections/ansible.windows/issues/297

How do I specify salt version for download in Vagrant to Virtualbox VM?

I am trying to stand up a series of VM's in Virtualbox via Vagrant (Master on Ubuntu 20.04, 7 Minions on Windows Server 2016 and 1 on Windows 10). During the execution of vagrant up I receive the following error on the first VM (Windows Server 2016) after the creation completes and Salt begins to attempt an installation:
==> VM24-APP-OSX-RISK: Checking for guest additions in VM...
==> VM24-APP-OSX-RISK: Setting hostname...
==> VM24-APP-OSX-RISK: Waiting for machine to reboot...
==> VM24-APP-OSX-RISK: Configuring and enabling network interfaces...
==> VM24-APP-OSX-RISK: Running provisioner: salt...
Copying salt minion config to vm.
Uploading minion keys.
Checking if C:\salt\salt-minion.bat is installed
C:\salt\salt-minion.bat was not found.
Checking if C:\salt\salt-call.bat is installed
C:\salt\salt-call.bat was not found.
Using Bootstrap Options: -P -c /tmp -x python3
Bootstrapping Salt... (this may take a while)
Defaulting to minion Python version 2
Service defaulting to run.
**Downloading Salt minion installer Salt-Minion-2018.3.3-Py2-AMD64-Setup.exe
WARNING: Retrying download in 2 seconds. Retry # 1
WARNING: Retrying download in 2 seconds. Retry # 2
WARNING: Retrying download in 2 seconds. Retry # 3
WARNING: Retrying download in 2 seconds. Retry # 4
The request was aborted: Could not create SSL/TLS secure channel.
At C:\tmp\bootstrap_salt.ps1:74 char:5
+ $webclient.DownloadFile($url, $file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], WebException
+ FullyQualifiedErrorId : WebException
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ErrorRecord System.Object
The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at CallSite.Target(Closure , CallSite , Object , Object , Object )
The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
powershell.exe -NonInteractive -NoProfile -executionpolicy bypass -file C:\tmp/bootstrap_salt.ps1 -P -c /tmp -x python3
Stdout from the command:
Defaulting to minion Python version 2
Service defaulting to run.
Downloading Salt minion installer Salt-Minion-2018.3.3-Py2-AMD64-Setup.exe
WARNING: Retrying download in 2 seconds. Retry # 1
WARNING: Retrying download in 2 seconds. Retry # 2
WARNING: Retrying download in 2 seconds. Retry # 3
WARNING: Retrying download in 2 seconds. Retry # 4
The request was aborted: Could not create SSL/TLS secure channel.
At C:\tmp\bootstrap_salt.ps1:74 char:5
+ $webclient.DownloadFile($url, $file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], WebException
+ FullyQualifiedErrorId : WebException
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ErrorRecord System.Object
The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at CallSite.Target(Closure , CallSite , Object , Object , Object )
Stderr from the command:
Looking at the installation guide for Salt for Windows (here: https://docs.saltstack.com/en/master/topics/installation/windows.html) - I am pretty sure the issue is that the executable is no longer in the main tree of the older supported builds, but has been moved to the Archive section, effectively breaking the link that I think the installer is trying to run with (Salt-Minion-2018.3.3-Py2-AMD64-Setup.exe). However, I do not see any way to specify the Salt version to use via the Vagrant file, the salt files or anywhere in the code.
Anyone got any ideas?

Ansible win_ping module getting timed out in windows

I am new to Ansible and trying to use win_ping module to ping a Windows Server 2016 (EC2 instance). Ansible is on RHEL 7.3 control machine, I have pip and pywinrm installed in control machine:
sudo pip install "pywinrm>=0.2.2"
This is my inventory file:
test ansible_connection=winrm ansible_host=34.210.164.63
[test_group]
test
[super_group:children]
test_group
[super_group:vars]
ansible_user=Administrator
ansible_password=XXXX
ansible_port=5986
ansible_winrm_server_cert_validation=ignore
This is the command I tried:
ansible all -i inventory -m win_ping
I am getting this error:
test | UNREACHABLE! => {
"changed": false,
"msg": "ssl: HTTPSConnectionPool(host='34.210.164.63', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x30df350>, 'Connection to 34.210.164.63 timed out. (connect timeout=30)'))",
"unreachable": true
}
In Windows Server 2016, Server Manager Remoting is already enabled by default, I validated it using Configure-SMremoting.exe -enable command. I did not made any configurations at Windows Server since this remoting is already enabled. Please let me know how to resolve this issue.
EDIT:
Not sure if these steps are required or notm but I tried enabling PowerShell Remoting using this command:
Enable-PSRemoting -Force
Then tried powershell.exe -File ConfigureRemotingForAnsible.ps1 and I an getting error:
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:128 char:13
+ </a> <a href="/business" class="js-selected-navigation-item na ...
+ ~
The '<' operator is reserved for future use.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:130 char:13
+ </a> <a href="/explore" class="js-selected-navigation-item nav ...
+ ~
The '<' operator is reserved for future use.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:132 char:17
+ </a> <a href="/marketplace" class="js-selected-navigation- ...
+ ~
The '<' operator is reserved for future use.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:134 char:13
+ </a> <a href="/pricing" class="js-selected-navigation-item nav ...
+ ~
The '<' operator is reserved for future use.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:136 char:11
+ </a> </nav>
+ ~
The '<' operator is reserved for future use.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:3221 char:227
+ ... g:0;display:inline"><input name="utf8" type="hidden" value="✓" ...
+ ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:3224 char:10
+ </form> </div>
+ ~
The '<' operator is reserved for future use.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:3252 char:11
+ <li>© 2017 <span title="0.13767s from github-fe-df0f95a.cp ...
+ ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:3252 char:23
+ <li>© 2017 <span title="0.13767s from github-fe-df0f95a.cp ...
+ ~
The '<' operator is reserved for future use.
At C:\Users\Administrator\Desktop\ConfigureRemotingForAnsible.ps1:3252 char:29
+ ... 2017 <span title="0.13767s from github-fe-df0f95a.cp1-iad.github.net ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'title="0.13767s from github-fe-df0f95a.cp1-iad.github.net">GitHub</span>' in expression or statement.
Not all parse errors were reported. Correct the reported errors and try again.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported
I guess I need to configure enable Remote Power Shell in my Windows Server to resolve this issue but not sure how to since I get the above erorr - please suggest.
I would go over windows logs. If they do not contain info you need - increase the verbosity.
Ping relies on winrm being up. WinRM needs execution policy changes, service configuration, ssl certificates, etc.
Maybe the safest path is to reconfigure ansible using the documentation.
The powershell remoting must be configured, in ec2 you can do this by adding user-data, running the script there, just paste the commands there.
Also, your ansible master machine must be able to connect to your target host, usually done by allowing it via security group, and creating the instance in that group.
So, in order to debug your stuff you should present the code/actions you did to setup security groups, possibly routes, and instance creation.
This is probably an AWS side issue not an ansible issue. Is your ansible server allowed to talk to your Windows EC2 instance via security group rules? By default everything is denied. You'll need to allow ICMP coming from the ansible server's address in the Windows EC2 instance's security group rules as well as from the windows server in the ansible server security group rules (if your ansible server is also an EC2 instance). If the ansible server is not an EC2 instance, make sure your firewall isn't blocking ICMP in or out for some reason.
Are these two servers on the same subnet/VPC within your account? If not, you'll have to create a VPC peering connection between the VPCs they are located on and edit route tables to point VPCs to the peering connection if traffic is coming from / going to the other VPC. The purpose of this is so that the two instances in separate VPCs can recognize and communicate with each other
I am probably late to the party, but I noticed the error you got when running powershell.exe -File ConfigureRemotingForAnsible.ps1. It's complaining about the syntax, and as far as I can tell you have HTML in that file. Did you maybe save the GitLab HTML page from the script?
Download the raw file here: https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 and try again.

Ruby list all files within a UNC path via WinRM

I am attempting to execute a ruby script via WinRM
ruby "R:\Scripts\testDir.rb"
that contains the following code:
Dir.foreach("\\\\FileServer\\TestDir\\") { |x|
puts "Found #{x}"
}
I have no problems executing the script locally on the server, but it fails with the following Permission Denied error via WinRM:
ruby : R:/Scripts/testDir.rb:1:in `open': Permission denied # dir_initialize - \\FileServer\TestDir\ (Errno::EACCES)
+ CategoryInfo : NotSpecified: (R:/Scripts...(Errno::EACCES):String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
from R:/Scripts/testDir.rb:1:in `foreach'
from R:/Scripts/testDir.rb:1:in `<main>'
When running the script locally, I get the following output.
Found .
Found ..
Found test.txt
Found test.tar.xz
My guess is that my script is failing because of the . and .. returned values being passed through WinRM, but I am not sure why.
The issue I was having was caused by double-hopping. The command I was running to execute the ruby script was from my local machine via WinRm.

Vagrant Error on Windows 10 with Hyper-V

After upgrading to windows 10 then running:
$ vagrant up
We get the following error message
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.
Script: get_vm_status.ps1
Error:
C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.4\plugins\providers\hyperv\scripts\get_vm_status.ps1 : Unable to
find type [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException].
At line:1 char:1
+ &('C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.4\plugins\prov ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Hyper...FailedException:TypeName) [get_vm_status.ps1], Ru
ntimeException
+ FullyQualifiedErrorId : TypeNotFound,get_vm_status.ps1
With Vagrant 1.7.4.
Any ideas?
I had the same problem on a fresh install of Vagrant 1.7.4 on Windows 10 Enteprise (first time using Vagrant).
It looks like the type VirtualizationOperationFailedException has been replaced with VirtualizationException in the latest version of PowerShell.
I changed line 15 of C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.4\plugins\providers\hyperv\scripts\get_vm_status.ps1 from:
} catch [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException] {
to
} catch [Microsoft.HyperV.PowerShell.VirtualizationException] {
Now I'm able to use vagrant up and vagrant status without errors. This is obviously not a long term solution but got things working again. There may be other scripts that are broken as well but I haven't run in to them yet.
I had the same error after destroying then recreating a VM.
I removed the .vagrant/machines/hyperv folder and all went ok.
If a solution by #jeff-r doesn't work for you, you can try changing:
} catch [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException] {
to:
} catch [Exception] {
Be careful, it may also cause some side-effects.
on win 10 you must disable "Hyper-V" to run vagrant/virtualbox

Resources