win_dsc using PolicyFileEditor DSC Module: failed to convert String to SINT32

58 views
Skip to first unread message

Ricardo Gaspar

unread,
Jun 15, 2017, 1:36:41 PM6/15/17
to Ansible Project
Hi all,

I was using the cAdministrativeTemplateSetting DSC Resource part of PolicyFileEditor module ( https://github.com/dlwyatt/PolicyFileEditor)  in a DSC script and it works fine. Here are the resource's properties:


cAdministrativeTemplateSetting
[String] #ResourceName
{
   
KeyValueName = [string]
   
PolicyType = [string]{ Administrators | Machine | NonAdministrators | User }
   
[Data = [string[]]]
   
[DependsOn = [string[]]]
   
[Ensure = [string]{ Absent | Present }]
   
[PsDscRunAsCredential = [PSCredential]]
   
[Type = [Int32]{ Binary | DWord | ExpandString | MultiString | None | QWord | String | Unknown }]
}



[write,ValueMap{"0","1","2","3","4","7","11","-1"},Values{"Unknown","String","ExpandString","Binary","DWord","MultiString","QWord","None"}] sint32 Type;


When using in my DSC script it works fine, I can use DWord or String as an argument for the Type property. Check my Script:

Configuration LocalGPO
{
    param
   
(
       
[string[]] $NodeName = 'localhost'
   
)


   
Import-DSCResource -ModuleName PolicyFileEditor


   
Node $NodeName
   
{


        cAdministrativeTemplateSetting
"RDP Users Home Directory Path"
       
{
       
#    SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDirUNC
       
#    SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDir
       
#    SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services!WFHomeDirDrive
           
KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDir"
           
PolicyType = "Machine"
           
Data = "\\servershare\test"
           
Ensure = "Present"
           
Type = "String"
       
}


        cAdministrativeTemplateSetting
"RDP Users Home Directory Letter"
       
{
           
KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDirDrive"
           
PolicyType = "Machine"
           
Data = "X:"
           
Ensure = "Present"
           
Type = "String"
       
}


        cAdministrativeTemplateSetting
"RDP Users Home Directory UNC boolean"
       
{
           
KeyValueName = "SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services\WFHomeDirUNC"
           
PolicyType = "Machine"
           
Data = "1"
           
Ensure = "Present"
           
Type = "Dword"
       
}


   
}




}


LocalGPO
Start-DscConfiguration -Path .\LocalGPO -Wait -Force -Verbose

My Ansible Script (first attempt):
---
 
- hosts: windows-ansible
   tasks
:
# GPO rule


   
- name: "RDP Users Home Directory Path"
     win_dsc
:
      resource_name
: cAdministrativeTemplateSetting
     
Ensure: "Present"
     
KeyValueName: "SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDir"
     
PolicyType: "Machine"
     
Data: "\\\\servershare\\test"


   
- name: "RDP Users Home Directory Letter"
     win_dsc
:
      resource_name
: cAdministrativeTemplateSetting
     
Ensure: "Present"
     
KeyValueName: "SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDirDrive"
     
PolicyType: "Machine"
     
Data: "X:"


   
- name: "RDP Users Home Directory UNC boolean"
     win_dsc
:
      resource_name
: cAdministrativeTemplateSetting
     
Ensure: "Present"
     
KeyValueName: "SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDirUNC"
     
PolicyType: "Machine"
     
Data: 1 #Also tried with: "1"
     
Type: Dword # Also tried with: "DWord"; "[Microsoft.Win32.RegistryValueKind]::DWord"


...


But in Ansible, using win_dsc I can't use these keywords (Dword, String). It will fail with the error:


fatal
: [mymachine.mydomain.com]: FAILED! => {"Data": "1", "Ensure": "Present", "KeyValueName": "SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDirUNC", "PolicyType": "Machine", "Type": "Dword", "attributes": [{"Key": "Type", "Name": "Type", "Value": "Dword"}, {"Key": "Ensure", "Name": "Ensure", "Value": "Present"}, {"Key": "Data", "Name": "Data", "Value": "1"}, {"Key": "KeyValueName", "Name": "KeyValueName", "Value": "SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDirUNC"}, {"Key": "PolicyType", "Name": "PolicyType", "Value": "Machine"}], "changed": false, "dsc_attributes": {"Data": "1", "Ensure": "Present", "KeyValueName": "SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDirUNC", "PolicyType": "Machine", "Type": "Dword"}, "failed": true, "msg": "Convert property 'Type' value from type 'STRING' to type 'SINT32' failed\r\n At line:12, char:2\r\n Buffer:\r\nirectResourceAccess\";\n};^\n\ninsta\r\n", "reboot_required": null, "resource_name": "cAdministrativeTemplateSetting"}


In the end, I managed to put it to work using the integer value that corresponded to DWord, but I would expect that DWord keyword would work on win_dsc.

   - name: "RDP Users Home Directory UNC boolean"
     win_dsc
:
      resource_name
: cAdministrativeTemplateSetting
     
Ensure: "Present"
     
KeyValueName: "SOFTWARE\\Policies\\Microsoft\\Windows NT\\Terminal Services\\WFHomeDirUNC"
     
PolicyType: "Machine"
     
Data: "1"
     
Type: 4 #DWord #"[Microsoft.Win32.RegistryValueKind]::DWord" #
     
## from the MOF file:
     
## [write,ValueMap{"0","1","2","3","4","7","11","-1"},Values{"Unknown","String","ExpandString","Binary","DWord","MultiString","QWord","None"}] sint32 Type;
...


Jordan Borean

unread,
Jun 15, 2017, 7:27:34 PM6/15/17
to Ansible Project
Hey

Thanks for the info you've posted, win_dsc has only been recently merged. Without knowing too much about how it works it seems like this is a bug with the module and it would be beneficial to raise an Issue at https://github.com/ansible/ansible.

Thanks

Jordan
Reply all
Reply to author
Forward
0 new messages