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