Actions supported by dsc_resource


#1

I was attempting to leverage a dsc_resource resource with an action of :nothing so that I can use it from another resource to notify it when it is needed. However when I looked at the dsc_resource documentation, I can only find two actions listed: :nothing and :reboot_action.

This leads to a perplexing problem: how am I supposed to notify the dsc_resource to execute from the calling resource? The documentation does not provide any available actions for doing so. This lead me to try and 'guess' the action by giving the action :execute, but chef barffed at this. However, thankfully, chef reported in the exception, Did you mean ':run?' I then tried this, and it seems to work great.

My bottom line question is: what is the definitive list of all the actions supported by this resource? And, can we get the documentation updated to reflect all of the available actions for this resource? I imagine that since :run is valid, there are probably more actions that will work for this resource as well.


#2

Yes, unfortunately this looks like a document that is out of sync with the real actions. There is only a single action :run that you found alongside :nothing. We'll get the docs updated. reboot_action in this case is a property that lets you decide whether to do as much work as possible before rebooting, or to reboot whenever DSC requests a reboot.

For a life hack here, assuming you have a Chef Workstation or recent ChefDK build you can use the chef-resource-inspector tool to dump out the valid actions, default action and all the available properties as JSON:

PS> chef-resource-inspector dsc_resource
{
  "dsc_resource": {
    "description": "The dsc_resource resource allows any DSC resource to be used in a Chef recipe, as well as any custom resources that have been added to your Windows PowerShell environment. Microsoft frequently adds new resources to the DSC resource collection.",
    "default_action": [
      "run"
    ],
    "actions": [
      "nothing",
      "run"
    ],
    "examples": null,
    "introduced": "12.2",
    "preview": false,
    "properties": [
      {
        "name": "name",
        "description": null,
        "introduced": null,
        "is": "String",
        "deprecated": false,
        "required": true,
        "default": null,
        "name_property": false
      },
      {
        "name": "retries",
        "description": null,
        "introduced": null,
        "is": "Integer",
        "deprecated": false,
        "required": false,
        "default": 0,
        "name_property": false
      },
      {
        "name": "retry_delay",
        "description": null,
        "introduced": null,
        "is": "Integer",
        "deprecated": false,
        "required": false,
        "default": 2,
        "name_property": false
      },
      {
        "name": "sensitive",
        "description": null,
        "introduced": null,
        "is": [
          "TrueClass",
          "FalseClass"
        ],
        "deprecated": false,
        "required": false,
        "default": false,
        "name_property": false
      },
      {
        "name": "ignore_failure",
        "description": null,
        "introduced": null,
        "is": [
          true,
          false,
          "quiet",
          "quiet"
        ],
        "deprecated": false,
        "required": false,
        "default": false,
        "name_property": false
      },
      {
        "name": "module_version",
        "description": "The version number of the module to use. PowerShell 5.0.10018.0 (or higher) supports having multiple versions of a module installed. This should be specified along with the module_name.",
        "introduced": "12.21",
        "is": "String",
        "deprecated": false,
        "required": false,
        "default": null,
        "name_property": false
      },
      {
        "name": "reboot_action",
        "description": "Use to request an immediate reboot or to queue a reboot using the :reboot_now (immediate reboot) or :request_reboot (queued reboot) actions built into the reboot resource.",
        "introduced": "12.6",
        "is": "Symbol",
        "deprecated": false,
        "required": false,
        "default": ":nothing",
        "name_property": false
      },
      {
        "name": "timeout",
        "description": "The amount of time (in seconds) a command is to wait before timing out.",
        "introduced": "12.6",
        "is": "Integer",
        "deprecated": false,
        "required": false,
        "default": null,
        "name_property": false
      }
    ]
  }
}

Stuart


#3

Thanks for the reply and info. I wasn't aware of the chef-resource-inspector; really cool!