diff --git a/lib/ansible/modules/windows/win_credential.ps1 b/lib/ansible/modules/windows/win_credential.ps1 index 7d44a476226..ff9ab045244 100644 --- a/lib/ansible/modules/windows/win_credential.ps1 +++ b/lib/ansible/modules/windows/win_credential.ps1 @@ -555,7 +555,7 @@ if ($null -ne $secret) { if ($secret_format -eq "base64") { $secret = [System.Convert]::FromBase64String($secret) } else { - $secret = [System.Text.Encoding]::UTF8.GetBytes($secret) + $secret = [System.Text.Encoding]::Unicode.GetBytes($secret) } } diff --git a/lib/ansible/modules/windows/win_credential.py b/lib/ansible/modules/windows/win_credential.py index 6912f6b7e8c..3782451e6db 100644 --- a/lib/ansible/modules/windows/win_credential.py +++ b/lib/ansible/modules/windows/win_credential.py @@ -45,7 +45,8 @@ options: data_format: description: - Controls the input type for I(data). - - If C(text), I(data) is a text string that is UTF-8 encoded to bytes. + - If C(text), I(data) is a text string that is UTF-16LE encoded to + bytes. - If C(base64), I(data) is a base64 string that is base64 decoded to bytes. type: str @@ -88,7 +89,7 @@ options: secret_format: description: - Controls the input type for I(secret). - - If C(text), I(secret) is a text string that is UTF-8 encoded to bytes. + - If C(text), I(secret) is a text string that is UTF-16LE encoded to bytes. - If C(base64), I(secret) is a base64 string that is base64 decoded to bytes. type: str diff --git a/test/integration/targets/win_credential/tasks/tests.yml b/test/integration/targets/win_credential/tasks/tests.yml index 98ae256ccff..f671c3c494e 100644 --- a/test/integration/targets/win_credential/tasks/tests.yml +++ b/test/integration/targets/win_credential/tasks/tests.yml @@ -409,6 +409,10 @@ register: generic_password_actual vars: *become_vars +- name: set encoded password result + set_fact: + encoded_pass: '{{ "genericpass" | string | b64encode(encoding="utf-16-le") }}' + - name: assert create generic password assert: that: @@ -419,7 +423,7 @@ - generic_password_actual.comment == None - generic_password_actual.name == test_hostname - generic_password_actual.persistence == "Enterprise" - - generic_password_actual.secret == "genericpass"|b64encode + - generic_password_actual.secret == encoded_pass - generic_password_actual.type == "Generic" - generic_password_actual.username == "genericuser"