New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows FQDN lookup in WinRM setup #40535

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
4 participants
@Footur

Footur commented May 22, 2018

SUMMARY

The WinRM setup Powershell script looks for the FQDN, but after executing this point I got the following error message:

Exception calling "GetHostByName" with "1" argument(s): "No such host is known"
At line:1 char:1
+ [System.Net.Dns]::GetHostByName(($env:computerName)).HostName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SocketException

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ConfigureRemotingForAnsible.ps1

ANSIBLE VERSION
ansible 2.5.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/foobar/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]

ADDITIONAL INFORMATION

OS: Microsoft Windows Server 2012 R2

If you want to reproduce the error, execute the following command:

[System.Net.Dns]::GetHostByName(($env:computerName)).Hostname

Update ConfigureRemotingForAnsible.ps1
Fixed a FQDN look up error.
@ansibot

This comment has been minimized.

Contributor

ansibot commented May 22, 2018

The test ansible-test sanity --test pslint [explain] failed with 2 errors:

examples/scripts/ConfigureRemotingForAnsible.ps1:96:18: PSAvoidUsingWMICmdlet File 'ConfigureRemotingForAnsible.ps1' uses WMI cmdlet. For PowerShell 3.0 and above, use CIM cmdlet which perform the same tasks as the WMI cmdlets. The CIM cmdlets comply with WS-Management (WSMan) standards and with the Common Information Model (CIM) standard, which enables the cmdlets to use the same techniques to manage Windows computers and those running other operating systems.
examples/scripts/ConfigureRemotingForAnsible.ps1:96:71: PSAvoidUsingWMICmdlet File 'ConfigureRemotingForAnsible.ps1' uses WMI cmdlet. For PowerShell 3.0 and above, use CIM cmdlet which perform the same tasks as the WMI cmdlets. The CIM cmdlets comply with WS-Management (WSMan) standards and with the Common Information Model (CIM) standard, which enables the cmdlets to use the same techniques to manage Windows computers and those running other operating systems.

click here for bot help

@@ -93,7 +93,7 @@ Function New-LegacySelfSignedCert
)
$hostnonFQDN = $env:computerName
$hostFQDN = [System.Net.Dns]::GetHostByName(($env:computerName)).Hostname
$hostFQDN = (Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain.ToLower()

This comment has been minimized.

@jborean93

jborean93 May 24, 2018

Contributor

This has 2 issues

  • In the case of the host not being in a domain, this would results in hostname.workgroup which isn't really correct?
  • We should be using the CIM cmdlets over the WMI ones, e.g. Get-CimInstance -ClassName Win32_ComputerSystem

I'm thinking we could do something like the following

$hostFQDN = $null
$computer_info = Get-CimInstance -ClassName Win32_ComputerSystem -Property DNSHostName, Domain, DomainRole
# 0 is workstation standalone and 2 is server standalone
if ($computer_info.DomainRole -notin @(0, 2)) {
    $hostFQDN = "$($computer_info.DNSHostName).$($computer_info.Domain)".ToLower()
}

From there we then only add it to the alternative names array further down if hostFQDN is not null.

@ansibot ansibot added the stale_ci label Jun 1, 2018

@ansibot ansibot added the small_patch label Jun 25, 2018

@dagwieers

This comment has been minimized.

Member

dagwieers commented Nov 29, 2018

What's needed to get this thing moving forward ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment