From 7be39ca5532cc2ab46b53fa9cb1152ca58fb3d81 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Mon, 16 Jan 2017 20:39:58 +0100 Subject: [PATCH] Windows modules: Add -type "path" to path parameters (#20282) This PR is based on #20164 functionality to specify the parameter type (e.g. as done for python modules). In this case only -type "path" has a specific meaning, as it will expand environment variables for paths. Which is typically done on Windows. So you can do: - win_copy: src: files/some.doc dest: '%UserProfile%\My Documents' --- lib/ansible/modules/windows/setup.ps1 | 2 +- lib/ansible/modules/windows/win_command.ps1 | 6 +++--- lib/ansible/modules/windows/win_copy.ps1 | 4 ++-- lib/ansible/modules/windows/win_file_version.ps1 | 2 +- lib/ansible/modules/windows/win_get_url.ps1 | 2 +- lib/ansible/modules/windows/win_robocopy.ps1 | 4 ++-- lib/ansible/modules/windows/win_say.ps1 | 6 +++--- lib/ansible/modules/windows/win_scheduled_task.ps1 | 2 +- lib/ansible/modules/windows/win_shell.ps1 | 8 ++++---- lib/ansible/modules/windows/win_unzip.ps1 | 6 +++--- lib/ansible/modules/windows/win_uri.ps1 | 2 +- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/ansible/modules/windows/setup.ps1 b/lib/ansible/modules/windows/setup.ps1 index fef2ade25c..4cddc0fff5 100644 --- a/lib/ansible/modules/windows/setup.ps1 +++ b/lib/ansible/modules/windows/setup.ps1 @@ -44,7 +44,7 @@ $result = New-Object psobject @{ }; # failifempty = $false is default and thus implied -$factpath = Get-AnsibleParam -obj $params -name fact_path +$factpath = Get-AnsibleParam -obj $params -name fact_path -type "path" if ($factpath -ne $null) { # Get any custom facts Get-CustomFacts -factpath $factpath diff --git a/lib/ansible/modules/windows/win_command.ps1 b/lib/ansible/modules/windows/win_command.ps1 index 316654b81d..4dd3df986e 100644 --- a/lib/ansible/modules/windows/win_command.ps1 +++ b/lib/ansible/modules/windows/win_command.ps1 @@ -25,9 +25,9 @@ $ErrorActionPreference = "Stop" $parsed_args = Parse-Args $args $false $raw_command_line = $(Get-AnsibleParam $parsed_args "_raw_params" -failifempty $true).Trim() -$chdir = Get-AnsibleParam $parsed_args "chdir" -$creates = Get-AnsibleParam $parsed_args "creates" -$removes = Get-AnsibleParam $parsed_args "removes" +$chdir = Get-AnsibleParam $parsed_args "chdir" -type "path" +$creates = Get-AnsibleParam $parsed_args "creates" -type "path" +$removes = Get-AnsibleParam $parsed_args "removes" -type "path" $result = @{changed=$true; warnings=@(); cmd=$raw_command_line} diff --git a/lib/ansible/modules/windows/win_copy.ps1 b/lib/ansible/modules/windows/win_copy.ps1 index 4a83e091c5..9f8a72a824 100644 --- a/lib/ansible/modules/windows/win_copy.ps1 +++ b/lib/ansible/modules/windows/win_copy.ps1 @@ -19,13 +19,13 @@ $params = Parse-Args $args -$src= Get-Attr $params "src" $FALSE +$src = Get-Attr $params "src" $FALSE -type "path" If ($src -eq $FALSE) { Fail-Json (New-Object psobject) "missing required argument: src" } -$dest= Get-Attr $params "dest" $FALSE +$dest = Get-Attr $params "dest" $FALSE -type "path" If ($dest -eq $FALSE) { Fail-Json (New-Object psobject) "missing required argument: dest" diff --git a/lib/ansible/modules/windows/win_file_version.ps1 b/lib/ansible/modules/windows/win_file_version.ps1 index 2e2f341c46..21145913bf 100644 --- a/lib/ansible/modules/windows/win_file_version.ps1 +++ b/lib/ansible/modules/windows/win_file_version.ps1 @@ -26,7 +26,7 @@ $result = New-Object psobject @{ changed = $false } -$path = Get-AnsibleParam $params "path" -failifempty $true -resultobj $result +$path = Get-AnsibleParam $params "path" -type "path" -failifempty $true -resultobj $result If (-Not (Test-Path -Path $path -PathType Leaf)){ Fail-Json $result "Specfied path $path does exist or is not a file." diff --git a/lib/ansible/modules/windows/win_get_url.ps1 b/lib/ansible/modules/windows/win_get_url.ps1 index f24b874046..05855f5044 100644 --- a/lib/ansible/modules/windows/win_get_url.ps1 +++ b/lib/ansible/modules/windows/win_get_url.ps1 @@ -27,7 +27,7 @@ $result = New-Object psobject @{ } $url = Get-AnsibleParam $params -name "url" -failifempty $true -$dest = Get-AnsibleParam $params -name "dest" -failifempty $true +$dest = Get-AnsibleParam $params -name "dest" -type "path" -failifempty $true $skip_certificate_validation = Get-AnsibleParam $params -name "skip_certificate_validation" -default $false $skip_certificate_validation = $skip_certificate_validation | ConvertTo-Bool diff --git a/lib/ansible/modules/windows/win_robocopy.ps1 b/lib/ansible/modules/windows/win_robocopy.ps1 index 24f041a287..2cd760da04 100644 --- a/lib/ansible/modules/windows/win_robocopy.ps1 +++ b/lib/ansible/modules/windows/win_robocopy.ps1 @@ -27,8 +27,8 @@ $result = New-Object psobject @{ changed = $false } -$src = Get-AnsibleParam -obj $params -name "src" -failifempty $true -$dest = Get-AnsibleParam -obj $params -name "dest" -failifempty $true +$src = Get-AnsibleParam -obj $params -name "src" -type "path" -failifempty $true +$dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true $purge = ConvertTo-Bool (Get-AnsibleParam -obj $params -name "purge" -default $false) $recurse = ConvertTo-Bool (Get-AnsibleParam -obj $params -name "recurse" -default $false) $flags = Get-AnsibleParam -obj $params -name "flags" -default $null diff --git a/lib/ansible/modules/windows/win_say.ps1 b/lib/ansible/modules/windows/win_say.ps1 index 2a1a0c18aa..d043b50db0 100644 --- a/lib/ansible/modules/windows/win_say.ps1 +++ b/lib/ansible/modules/windows/win_say.ps1 @@ -22,9 +22,9 @@ $params = Parse-Args $args; $result = New-Object PSObject; $msg = Get-AnsibleParam -obj $params -name "msg" -$msg_file = Get-AnsibleParam -obj $params -name "msg_file" -$start_sound_path = Get-AnsibleParam -obj $params -name "start_sound_path" -$end_sound_path = Get-AnsibleParam -obj $params -name "end_sound_path" +$msg_file = Get-AnsibleParam -obj $params -name "msg_file" -type "path" +$start_sound_path = Get-AnsibleParam -obj $params -name "start_sound_path" -type "path" +$end_sound_path = Get-AnsibleParam -obj $params -name "end_sound_path" -type "path" $voice = Get-AnsibleParam -obj $params -name "voice" $speech_speed = Get-AnsibleParam -obj $params -name "speech_speed" $speed = 0 diff --git a/lib/ansible/modules/windows/win_scheduled_task.ps1 b/lib/ansible/modules/windows/win_scheduled_task.ps1 index 70ba45e29d..8804028345 100644 --- a/lib/ansible/modules/windows/win_scheduled_task.ps1 +++ b/lib/ansible/modules/windows/win_scheduled_task.ps1 @@ -28,7 +28,7 @@ $days_of_week = Get-AnsibleParam $params -name "days_of_week" $enabled = Get-AnsibleParam $params -name "enabled" -default $true $enabled = $enabled | ConvertTo-Bool $description = Get-AnsibleParam $params -name "description" -default " " -$path = Get-AnsibleParam $params -name "path" +$path = Get-AnsibleParam $params -name "path" -type "path" $argument = Get-AnsibleParam $params -name "argument" $result = New-Object PSObject; diff --git a/lib/ansible/modules/windows/win_shell.ps1 b/lib/ansible/modules/windows/win_shell.ps1 index 664858e52c..3e844d67c6 100644 --- a/lib/ansible/modules/windows/win_shell.ps1 +++ b/lib/ansible/modules/windows/win_shell.ps1 @@ -63,10 +63,10 @@ namespace Ansible.Shell $parsed_args = Parse-Args $args $false $raw_command_line = $(Get-AnsibleParam $parsed_args "_raw_params" -failifempty $true).Trim() -$chdir = Get-AnsibleParam $parsed_args "chdir" -$executable = Get-AnsibleParam $parsed_args "executable" -$creates = Get-AnsibleParam $parsed_args "creates" -$removes = Get-AnsibleParam $parsed_args "removes" +$chdir = Get-AnsibleParam $parsed_args "chdir" -type "path" +$executable = Get-AnsibleParam $parsed_args "executable" -type "path" +$creates = Get-AnsibleParam $parsed_args "creates" -type "path" +$removes = Get-AnsibleParam $parsed_args "removes" -type "path" $result = @{changed=$true; warnings=@(); cmd=$raw_command_line} diff --git a/lib/ansible/modules/windows/win_unzip.ps1 b/lib/ansible/modules/windows/win_unzip.ps1 index 59fbd33166..b91712f2be 100644 --- a/lib/ansible/modules/windows/win_unzip.ps1 +++ b/lib/ansible/modules/windows/win_unzip.ps1 @@ -27,14 +27,14 @@ $result = New-Object psobject @{ changed = $false } -$creates = Get-AnsibleParam -obj $params -name "creates" +$creates = Get-AnsibleParam -obj $params -name "creates" -type "path" If ($creates -ne $null) { If (Test-Path $params.creates) { Exit-Json $result "The 'creates' file or directory already exists." } } -$src = Get-AnsibleParam -obj $params -name "src" -failifempty $true +$src = Get-AnsibleParam -obj $params -name "src" -type "path" -failifempty $true If (-Not (Test-Path -path $src)){ Fail-Json $result "src file: $src does not exist." } @@ -42,7 +42,7 @@ If (-Not (Test-Path -path $src)){ $ext = [System.IO.Path]::GetExtension($src) -$dest = Get-AnsibleParam -obj $params -name "dest" -failifempty $true +$dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true If (-Not (Test-Path $dest -PathType Container)){ Try{ New-Item -itemtype directory -path $dest diff --git a/lib/ansible/modules/windows/win_uri.ps1 b/lib/ansible/modules/windows/win_uri.ps1 index 3f0b44861d..5b151b105f 100644 --- a/lib/ansible/modules/windows/win_uri.ps1 +++ b/lib/ansible/modules/windows/win_uri.ps1 @@ -42,7 +42,7 @@ $method = Get-AnsibleParam -obj $params "method" -default "GET" $content_type = Get-AnsibleParam -obj $params -name "content_type" $headers = Get-AnsibleParam -obj $params -name "headers" $body = Get-AnsibleParam -obj $params -name "body" -$dest = Get-AnsibleParam -obj $params -name "dest" -default $null +$dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -default $null $use_basic_parsing = ConvertTo-Bool (Get-AnsibleParam -obj $params -name "use_basic_parsing" -default $true) $webrequest_opts.Uri = $url