mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win_msg: Added integration tests, parameter fixes (#26126)
This commit is contained in:
parent
3ba4fc2d54
commit
bb7ebc6a55
4 changed files with 54 additions and 22 deletions
|
@ -24,40 +24,39 @@ $stopwatch = [system.diagnostics.stopwatch]::startNew()
|
|||
$params = Parse-Args $args -supports_check_mode $true
|
||||
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
||||
|
||||
$display_seconds = Get-AnsibleParam -obj $params -name display_seconds -default "10" -failifempty $False -resultobj $result
|
||||
$msg = Get-AnsibleParam -obj $params -name msg -default "Hello world!" -resultobj $result
|
||||
$to = Get-AnsibleParam -obj $params -name to -default "*" -failifempty $False -resultobj $result
|
||||
$wait = Get-AnsibleParam -obj $params -name wait -default $False -failifempty $False -resultobj $result
|
||||
$display_seconds = Get-AnsibleParam -obj $params -name "display_seconds" -type "int" -default "10"
|
||||
$msg = Get-AnsibleParam -obj $params -name "msg" -type "str" -default "Hello world!"
|
||||
$to = Get-AnsibleParam -obj $params -name "to" -type "str" -default "*"
|
||||
$wait = Get-AnsibleParam -obj $params -name "wait" -type "bool" -default $false
|
||||
|
||||
$result = @{
|
||||
changed = $false
|
||||
display_seconds = $display_seconds
|
||||
msg = $msg
|
||||
wait = $wait
|
||||
}
|
||||
|
||||
|
||||
$msg_args = @($to, "/TIME:$display_seconds")
|
||||
|
||||
If ($wait) {
|
||||
if ($wait) {
|
||||
$msg_args += "/W"
|
||||
}
|
||||
|
||||
$msg_args += $msg
|
||||
if (-not $check_mode) {
|
||||
$ret = & msg.exe $msg_args 2>&1
|
||||
$output = & msg.exe $msg_args 2>&1
|
||||
$result.rc = $LASTEXITCODE
|
||||
}
|
||||
|
||||
$endsend_at = Get-Date| Out-String
|
||||
$stopwatch.Stop()
|
||||
|
||||
$result.changed = $True
|
||||
$result.display_seconds = $display_seconds
|
||||
$result.msg = $msg
|
||||
$result.changed = $true
|
||||
$result.runtime_seconds = $stopwatch.Elapsed.TotalSeconds
|
||||
$result.sent_localtime = $endsend_at.Trim()
|
||||
$result.wait = $wait
|
||||
|
||||
If (-not $result.rc -eq 0 ) {
|
||||
Fail-Json $result "$ret"
|
||||
if ($result.rc -ne 0 ) {
|
||||
Fail-Json $result "$output"
|
||||
}
|
||||
|
||||
Exit-Json $result
|
||||
|
|
|
@ -25,7 +25,6 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
|
|||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: win_msg
|
||||
|
@ -47,13 +46,14 @@ options:
|
|||
- Whether to wait for users to respond. Module will only wait for the number of seconds specified in display_seconds or 10 seconds if not specified.
|
||||
However, if I(wait) is true, the message is sent to each logged on user in turn, waiting for the user to either press 'ok' or for
|
||||
the timeout to elapse before moving on to the next user.
|
||||
required: false
|
||||
default: false
|
||||
type: bool
|
||||
default: 'no'
|
||||
msg:
|
||||
description:
|
||||
- The text of the message to be displayed.
|
||||
default: Hello world!
|
||||
author: "Jon Hawkesworth (@jhawkesworth)"
|
||||
author:
|
||||
- Jon Hawkesworth (@jhawkesworth)
|
||||
notes:
|
||||
- This module must run on a windows host, so ensure your play targets windows
|
||||
hosts, or delegates to a windows host.
|
||||
|
@ -63,10 +63,10 @@ notes:
|
|||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
# Warn logged in users of impending upgrade
|
||||
- name: Warn logged in users of impending upgrade
|
||||
win_msg:
|
||||
display_seconds: 60
|
||||
msg: "Automated upgrade about to start. Please save your work and log off before {{ deployment_start_time }}"
|
||||
msg: Automated upgrade about to start. Please save your work and log off before {{ deployment_start_time }}
|
||||
'''
|
||||
|
||||
RETURN = r'''
|
||||
|
@ -74,12 +74,17 @@ msg:
|
|||
description: Test of the message that was sent.
|
||||
returned: changed
|
||||
type: string
|
||||
sample: "Automated upgrade about to start. Please save your work and log off before 22 July 2016 18:00:00"
|
||||
sample: Automated upgrade about to start. Please save your work and log off before 22 July 2016 18:00:00
|
||||
display_seconds:
|
||||
description: Value of display_seconds module parameter.
|
||||
returned: success
|
||||
type: string
|
||||
sample: 10
|
||||
rc:
|
||||
description: The return code of the API call
|
||||
returned: always
|
||||
type: int
|
||||
sample: 0
|
||||
runtime_seconds:
|
||||
description: How long the module took to run on the remote windows host.
|
||||
returned: success
|
||||
|
|
1
test/integration/targets/win_msg/aliases
Normal file
1
test/integration/targets/win_msg/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
windows/ci/group2
|
27
test/integration/targets/win_msg/tasks/main.yml
Normal file
27
test/integration/targets/win_msg/tasks/main.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
- name: Warn user
|
||||
win_msg:
|
||||
display_seconds: 10
|
||||
msg: Keep calm and carry on.
|
||||
register: msg_result
|
||||
|
||||
- name: Test msg_result
|
||||
assert:
|
||||
that:
|
||||
- not msg_result|failed
|
||||
- msg_result|changed
|
||||
- msg_result.runtime_seconds < 10
|
||||
|
||||
- name: Warn user and wait for it
|
||||
win_msg:
|
||||
display_seconds: 5
|
||||
msg: Keep calm and carry on.
|
||||
#to: '{{ ansible_user }}'
|
||||
wait: yes
|
||||
register: msg_wait_result
|
||||
|
||||
- name: Test msg_wait_result
|
||||
assert:
|
||||
that:
|
||||
- not msg_wait_result|failed
|
||||
- msg_wait_result|changed
|
||||
- msg_wait_result.runtime_seconds > 5
|
Loading…
Reference in a new issue