From 08bf65630997dda4260bb633dcf3753cfc426d03 Mon Sep 17 00:00:00 2001 From: Peter Mounce Date: Tue, 19 May 2015 11:21:23 +0100 Subject: [PATCH] Code-review Swap state enabled/disabled -> enabled yes/no --- .../extras/windows/win_scheduled_task.ps1 | 24 ++++++++----------- .../extras/windows/win_scheduled_task.py | 10 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/ansible/modules/extras/windows/win_scheduled_task.ps1 b/lib/ansible/modules/extras/windows/win_scheduled_task.ps1 index 52b68dd5b6a..2f802f59cd0 100644 --- a/lib/ansible/modules/extras/windows/win_scheduled_task.ps1 +++ b/lib/ansible/modules/extras/windows/win_scheduled_task.ps1 @@ -33,34 +33,30 @@ else { Fail-Json $result "missing required argument: name" } -if ($params.state) +if ($params.enabled) { - $state = $params.state.ToString() - if (($state -ne 'Enabled') -and ($state -ne 'Disabled')) - { - Fail-Json $result "state is '$state'; must be 'Enabled' or 'Disabled'" - } + $enabled = $params.enabled | ConvertTo-Bool } else { - $state = "Enabled" + $enabled = $true } - +$target_state = @{$true = "Enabled"; $false="Disabled"}[$enabled] try { $tasks = Get-ScheduledTask -TaskPath $name - $tasks_needing_changing = $tasks |? { $_.State -ne $state } + $tasks_needing_changing = $tasks |? { $_.State -ne $target_state } if (-not($tasks_needing_changing -eq $null)) { - if ($state -eq 'Disabled') - { - $tasks_needing_changing | Disable-ScheduledTask - } - elseif ($state -eq 'Enabled') + if ($enabled) { $tasks_needing_changing | Enable-ScheduledTask } + else + { + $tasks_needing_changing | Disable-ScheduledTask + } Set-Attr $result "tasks_changed" ($tasks_needing_changing | foreach { $_.TaskPath + $_.TaskName }) $result.changed = $true } diff --git a/lib/ansible/modules/extras/windows/win_scheduled_task.py b/lib/ansible/modules/extras/windows/win_scheduled_task.py index 7c604ecec20..2c5867402c5 100644 --- a/lib/ansible/modules/extras/windows/win_scheduled_task.py +++ b/lib/ansible/modules/extras/windows/win_scheduled_task.py @@ -34,18 +34,18 @@ options: - Name of the scheduled task - Supports * as wildcard required: true - state: + enabled: description: - State that the task should become required: false choices: - - Disabled - - Enabled - default: Enabled + - yes + - no + default: yes author: Peter Mounce ''' EXAMPLES = ''' # Disable the scheduled tasks with "WindowsUpdate" in their name - win_scheduled_task: name="*WindowsUpdate*" state=disabled + win_scheduled_task: name="*WindowsUpdate*" enabled=no '''