summaryrefslogtreecommitdiff
path: root/lib/ansible/module_utils/powershell.ps1
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2014-06-19 10:36:53 -0500
committerMatt Martz <matt@sivel.net>2014-06-19 14:25:50 -0500
commit90c98ada7cccc3f8fddfeb83cfc97409b392184d (patch)
treeb1b7c838e43d81f4804dac72fb4ed3485851abb9 /lib/ansible/module_utils/powershell.ps1
parent04d94ffb8f107e8df48ff6955f83c97257cf9dcb (diff)
downloadansible-90c98ada7cccc3f8fddfeb83cfc97409b392184d.tar.gz
Add ConvertTo-Bool filter function in powershell common code
Diffstat (limited to 'lib/ansible/module_utils/powershell.ps1')
-rw-r--r--lib/ansible/module_utils/powershell.ps123
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/ansible/module_utils/powershell.ps1 b/lib/ansible/module_utils/powershell.ps1
index a911ea95dd..86c3c82e5b 100644
--- a/lib/ansible/module_utils/powershell.ps1
+++ b/lib/ansible/module_utils/powershell.ps1
@@ -64,3 +64,26 @@ Function Fail-Json($obj, $message)
echo $obj | ConvertTo-Json
Exit 1
}
+
+# Helper filter/pipeline function to convert a value to boolean following current
+# Ansible practices
+Function ConvertTo-Bool
+{
+ param(
+ [parameter(valuefrompipeline=$true)]
+ $obj
+ )
+
+ $boolean_strings = "yes", "on", "1", "true", 1
+ $obj_string = [string]$obj
+
+ if (($obj.GetType().Name -eq "Boolean" -and $obj) -or $boolean_strings -contains $obj_string.ToLower())
+ {
+ $true
+ }
+ Else
+ {
+ $false
+ }
+ return
+}