Windows: Updated docs to reflect the new name of get-attr, along with examples

This commit is contained in:
Trond Hindenes 2015-09-30 23:29:05 +02:00
parent 4cfcf5d61b
commit e9786db541

View file

@ -509,6 +509,7 @@ Windows modules checklist
* Favour native powershell and .net ways of doing things over calls to COM libraries or calls to native executables which may or may not be present in all versions of windows * Favour native powershell and .net ways of doing things over calls to COM libraries or calls to native executables which may or may not be present in all versions of windows
* modules are in powershell (.ps1 files) but the docs reside in same name python file (.py) * modules are in powershell (.ps1 files) but the docs reside in same name python file (.py)
* look at ansible/lib/ansible/module_utils/powershell.ps1 for common code, avoid duplication * look at ansible/lib/ansible/module_utils/powershell.ps1 for common code, avoid duplication
* Ansible uses strictmode so be sure to test with that enabled
* start with:: * start with::
#!powershell #!powershell
@ -518,18 +519,21 @@ then::
then:: then::
# WANT_JSON # WANT_JSON
# POWERSHELL_COMMON # POWERSHELL_COMMON
then, to parse all arguments into a variable modules generally use::
$params = Parse-Args $args
* Arguments: * Arguments:
* Try and use state present and state absent like other modules * Try and use state present and state absent like other modules
* You need to check that all your mandatory args are present:: * You need to check that all your mandatory args are present. You can do this using the builtin Get-AnsibleParam function.
* Required arguments::
If ($params.state) { $package = Get-AnsibleParam -obj $params -name name -failifempty $true
$state = $params.state.ToString().ToLower() * Required arguments with name validation::
If (($state -ne 'started') -and ($state -ne 'stopped') -and ($state -ne 'restarted')) { $state = Get-AnsibleParam -obj $params -name "State" -ValidateSet "Present","Absent" -resultobj $resultobj -failifempty $true
Fail-Json $result "state is '$state'; must be 'started', 'stopped', or 'restarted'" * Optional arguments with name validation::
} $state = Get-AnsibleParam -obj $params -name "State" -default "Present" -ValidateSet "Present","Absent"
} * the If "FailIfEmpty" is true, the resultobj parameter is used to specify the object returned to fail-json. You can also override the default message
using $emptyattributefailmessage (for missing required attributes) and $ValidateSetErrorMessage (for attribute validation errors)
* Look at existing modules for more examples of argument checking. * Look at existing modules for more examples of argument checking.
* Results * Results
@ -551,7 +555,6 @@ then::
* Have you tested for powershell 3.0 and 4.0 compliance? * Have you tested for powershell 3.0 and 4.0 compliance?
Deprecating and making module aliases Deprecating and making module aliases
`````````````````````````````````````` ``````````````````````````````````````