From 374ea94dc36444e800a2012edffc465b0b5ce032 Mon Sep 17 00:00:00 2001 From: Bartek Bielawski Date: Thu, 13 Jul 2017 01:50:29 +0200 Subject: [PATCH] Adding more explicit module syntax (#26722) Removing module_version from Attributes, support for class based resouces that need version specified when multiple version are present, support for File resource that has blank output for ModuleName/Version in Get-DscResource --- lib/ansible/modules/windows/win_dsc.ps1 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/windows/win_dsc.ps1 b/lib/ansible/modules/windows/win_dsc.ps1 index c6d970127c5..f40fc7632dd 100644 --- a/lib/ansible/modules/windows/win_dsc.ps1 +++ b/lib/ansible/modules/windows/win_dsc.ps1 @@ -37,7 +37,12 @@ $resourcename = Get-AnsibleParam -obj $params -name "resource_name" -type "str" $module_version = Get-AnsibleParam -obj $params -name "module_version" -type "str" -default "latest" #From Ansible 2.3 onwards, params is now a Hash Array -$Attributes = $params.GetEnumerator() | where {$_.key -ne "resource_name"} | where {$_.key -notlike "_ansible_*"} +$Attributes = $params.GetEnumerator() | + Where-Object { + $_.key -ne "resource_name" -and + $_.key -ne "module_version" -and + $_.key -notlike "_ansible_*" + } if (!($Attributes)) { @@ -91,7 +96,15 @@ if (!$Resource) #Get the Module that provides the resource. Will be used as #mandatory argument for Invoke-DscResource -$Module = $Resource.ModuleName +$Module = @{ + ModuleName = $Resource.ModuleName + ModuleVersion = $Resource.Version +} + +# Binary resources are not working very well with that approach - need to guesstimate module name/version +if ( -not ($Module.ModuleName -or $Module.ModuleVersion)) { + $Module = 'PSDesiredStateConfiguration' +} #grab the module version if we can try {