From 1b5975f17eb580b62ef823b0d3d7e667c8b866b6 Mon Sep 17 00:00:00 2001 From: ShachafGoldstein Date: Tue, 11 Jun 2019 22:25:39 +0300 Subject: [PATCH] Fixes #54550 (#56279) * "setup.ps1" - Change $env:COMPUTERNAME to [System.Net.Dns]::GetHostName(), to support non NETBIOS compliant hostnames * Change method to base on WMI * changed ansible_domain to use WMI * Fixed per review * Fixed dot stuff * Revert "Fixed dot stuff" This reverts commit a1d5be00f1c54e7d2576e468612c9a5bf16bb049. * dot stuff * dot stuff 2.0 * Update setup.ps1 * Wrap this up to go --- ...50-Change-windows-ansible-hostname-setup.yml | 2 ++ lib/ansible/modules/windows/setup.ps1 | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/54550-Change-windows-ansible-hostname-setup.yml diff --git a/changelogs/fragments/54550-Change-windows-ansible-hostname-setup.yml b/changelogs/fragments/54550-Change-windows-ansible-hostname-setup.yml new file mode 100644 index 00000000000..1b51cbd42d0 --- /dev/null +++ b/changelogs/fragments/54550-Change-windows-ansible-hostname-setup.yml @@ -0,0 +1,2 @@ +bugfixes: + - "setup.ps1 - Support non NETBIOS compliant hostnames (https://github.com/ansible/ansible/issues/54550)" \ No newline at end of file diff --git a/lib/ansible/modules/windows/setup.ps1 b/lib/ansible/modules/windows/setup.ps1 index 71f1b49b276..f4f392e6ddb 100644 --- a/lib/ansible/modules/windows/setup.ps1 +++ b/lib/ansible/modules/windows/setup.ps1 @@ -307,7 +307,13 @@ if($gather_subset.Contains('memory')) { if($gather_subset.Contains('platform')) { $win32_cs = Get-LazyCimInstance Win32_ComputerSystem $win32_os = Get-LazyCimInstance Win32_OperatingSystem - $ip_props = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties() + $domain_suffix = $win32_cs.Domain.Substring($win32_cs.Workgroup.length) + $fqdn = $win32_cs.DNSHostname + + if( $domain_suffix -ne "") + { + $fqdn = $win32_cs.DNSHostname + "." + $domain_suffix + } try { $ansible_reboot_pending = Get-PendingRebootStatus @@ -318,11 +324,12 @@ if($gather_subset.Contains('platform')) { $ansible_facts += @{ ansible_architecture = $win32_os.OSArchitecture - ansible_domain = $ip_props.DomainName - ansible_fqdn = ($ip_props.Hostname + "." + $ip_props.DomainName) - ansible_hostname = $env:COMPUTERNAME + ansible_domain = $domain_suffix + ansible_fqdn = $fqdn + ansible_hostname = $win32_cs.DNSHostname + ansible_netbios_name = $win32_cs.Name ansible_kernel = $osversion.Version.ToString() - ansible_nodename = ($ip_props.HostName + "." + $ip_props.DomainName) + ansible_nodename = $fqdn ansible_machine_id = Get-MachineSid ansible_owner_contact = ([string] $win32_cs.PrimaryOwnerContact) ansible_owner_name = ([string] $win32_cs.PrimaryOwnerName)