From 67fd98da090fa70be5c7b7e89a40d656c4d01733 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Tue, 3 Oct 2017 07:32:30 +1100 Subject: [PATCH] win_msg: added doc about msg limit and included an explicit check for better error handling (#31078) --- lib/ansible/modules/windows/win_msg.ps1 | 4 ++++ lib/ansible/modules/windows/win_msg.py | 1 + test/integration/targets/win_msg/tasks/main.yml | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/lib/ansible/modules/windows/win_msg.ps1 b/lib/ansible/modules/windows/win_msg.ps1 index 04cf80b2ba4..c3dd033afc9 100644 --- a/lib/ansible/modules/windows/win_msg.ps1 +++ b/lib/ansible/modules/windows/win_msg.ps1 @@ -36,6 +36,10 @@ $result = @{ wait = $wait } +if ($msg.Length -gt 255) { + Fail-Json -obj $result -message "msg length must be less than 256 characters, current length: $($msg.Length)" +} + $msg_args = @($to, "/TIME:$display_seconds") if ($wait) { diff --git a/lib/ansible/modules/windows/win_msg.py b/lib/ansible/modules/windows/win_msg.py index 53d211131f9..fa0250994bd 100644 --- a/lib/ansible/modules/windows/win_msg.py +++ b/lib/ansible/modules/windows/win_msg.py @@ -51,6 +51,7 @@ options: msg: description: - The text of the message to be displayed. + - The message must be less than 256 characters. default: Hello world! author: - Jon Hawkesworth (@jhawkesworth) diff --git a/test/integration/targets/win_msg/tasks/main.yml b/test/integration/targets/win_msg/tasks/main.yml index 255c5d0f729..0ab4dbf94ab 100644 --- a/test/integration/targets/win_msg/tasks/main.yml +++ b/test/integration/targets/win_msg/tasks/main.yml @@ -25,3 +25,9 @@ - not msg_wait_result|failed - msg_wait_result|changed - msg_wait_result.runtime_seconds > 5 + +- name: fail to send a message > 255 characters + win_msg: + msg: "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456" + register: fail_too_long + failed_when: "fail_too_long.msg != 'msg length must be less than 256 characters, current length: 256'"