From 94566ed79ca8448ed9322d3ed4ff3f04e8473c46 Mon Sep 17 00:00:00 2001 From: ShachafGoldstein Date: Tue, 28 May 2019 22:30:16 +0300 Subject: [PATCH] Win_hostname module: Change name check to WMI (#56420) * Change name check to WMI * Changelog fragment * Fixed per review --- .../fragments/56420-Fix-win_hostname-for-non-netbios-names.yml | 2 ++ lib/ansible/modules/windows/win_hostname.ps1 | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/56420-Fix-win_hostname-for-non-netbios-names.yml diff --git a/changelogs/fragments/56420-Fix-win_hostname-for-non-netbios-names.yml b/changelogs/fragments/56420-Fix-win_hostname-for-non-netbios-names.yml new file mode 100644 index 00000000000..a58144423ec --- /dev/null +++ b/changelogs/fragments/56420-Fix-win_hostname-for-non-netbios-names.yml @@ -0,0 +1,2 @@ +bugfixes: +- "win_hostname - Fix non netbios compliant name handling (https://github.com/ansible/ansible/issues/55283)" \ No newline at end of file diff --git a/lib/ansible/modules/windows/win_hostname.ps1 b/lib/ansible/modules/windows/win_hostname.ps1 index ff447321e02..5efe4d6b9e7 100644 --- a/lib/ansible/modules/windows/win_hostname.ps1 +++ b/lib/ansible/modules/windows/win_hostname.ps1 @@ -11,7 +11,8 @@ $params = Parse-Args $args -supports_check_mode $true $name = Get-AnsibleParam -obj $params -name "name" -type "str" -failifempty $true $check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false -$current_computer_name = $env:ComputerName +$current_computer_name = (Get-CimInstance -Class Win32_ComputerSystem).DNSHostname + $result = @{ changed = $false old_name = $current_computer_name