puppetlabs / puppetlabs-dsc_lite

DSC to Puppet runtime integration and module generation tasks
Apache License 2.0
8 stars 26 forks source link

Failed to serialize properties into CimInstance error in puppet #222

Open sara921-spec opened 2 days ago

sara921-spec commented 2 days ago

We are trying to use a class based resource from sqlserverDSC in puppet, while we try to do that we are running into the below error while applying it on the server using puppet. We just feel like it might be a bug with the DSC_lite? (I might be wrong, but wanted to see if it is actually a bug)

The code that we are using in puppet, (Array)

      permission => [
                      {
                        permission => ['ViewServerState'],
                        state => ['Grant']
                      }
                    ]

And the error that we are running into,

Could not evaluate: Failed to serialize properties into CimInstance.

Environment

brajjan commented 14 hours ago

Have a look at the Using CimInstance docs and the SqlServerDsc data type used for the Permission property

When using dsc_lite you need to be aware of the following

Since the dsc Puppet type has no prior knowledge of the type for each property in a DSC Resource, it can't format the hash correctly without some hints.

A DSC Resource may need a more complex type than a simple key value pair, for example, an EmbeddedInstance. An EmbeddedInstance is serialized as CimInstance over the wire. In order to represent a CimInstance in the dsc type, use the dsc_type key to specify which CimInstance to use. If the CimInstance is an array, append a [] to the end of the name.

For example, create a new IIS website using the xWebSite DSC Resource, bound to port 80. Use dsc_type to specify a MSFT_xWebBindingInformation CimInstance, and append [] to indicate that it is an array. Note that you do this even if you are only putting a single value in dsc_properties.

A contrived, but simple example follows:

dsc {'NewWebsite':
  resource_name => 'xWebsite',
  module        => 'xWebAdministration',
  properties    => {
    ensure       => 'Present',
    state        => 'Started',
    name         => 'TestSite',
    physicalpath => 'C:\testsite',
    bindinginfo  => {
      'dsc_type'       => 'MSFT_xWebBindingInformation[]',
      'dsc_properties' => {
        "protocol" => "HTTP",
        "port"     => 80
      }
    }
  }
}

So in your case it should work with something like

dsc {'ViewServerState Permissions':
  resource_name => 'SqlPermission',
  module        => 'SqlServerDsc',
  properties    => {
    permission => {
      'dsc_type'       => 'ServerPermission[]',
      'dsc_properties' => {
        'state'      => 'Grant',
        'permission' => ['ViewServerState'],
      },
    },
  },
}
sara921-spec commented 7 hours ago

Thanks for the reply @brajjan It was so helpful, but we kind of ran into this error now, might be something with the syntax, also we used exact code what u have it above.

Could not evaluate: PowerShell DSC resource SqlServerDsc  failed to execute Test functionality with error message: One or more permission states was missing. One of each permission state must be provided. (SP0008)
Parameter name: Permission
brajjan commented 7 hours ago

That is a message from the dsc resource. Do a puppet run with the --debug switch and look at the InvokeParams to see how puppet translated it.

Then you can have a closer look at it and test it locally the powershell way. Even add debug flag to the Invoke-DscResource command if needed. Or dig into the SqlServerDsc code to see how it needs to be set