salt.states.win_dsc_resource#
State module for managing Windows PowerShell DSC Resources via
Invoke-DscResource.
This module manages individual DSC resources without compiling a MOF file or
involving the Local Configuration Manager (LCM). Salt controls the idempotency:
it calls the resource's Test method first, and only calls Set if a
change is needed.
Use the psget module to install DSC resource modules from the PowerShell
Gallery before referencing them in states.
Example:
ensure_web_server:
dsc_resource.managed:
- name: WindowsFeature
- module_name: PSDesiredStateConfiguration
- properties:
Name: Web-Server
Ensure: Present
remove_telnet:
dsc_resource.managed:
- name: WindowsFeature
- module_name: PSDesiredStateConfiguration
- properties:
Name: Telnet-Client
Ensure: Absent
create_config_file:
dsc_resource.managed:
- name: File
- module_name: PSDesiredStateConfiguration
- properties:
DestinationPath: C:\App\config.txt
Ensure: Present
Contents: managed by Salt
New in version 3008.1.
- salt.states.win_dsc_resource.managed(name, module_name, properties)#
Ensure a DSC resource is in the desired state.
Calls
dsc_resource.testto check whether changes are needed. If the resource is already in the desired state, returns immediately with no changes. Otherwise callsdsc_resource.setto apply the configuration, then verifies the result with anotherdsc_resource.testcall.The
changesdictionary uses the actual before and after values returned bydsc_resource.get, giving a real diff of the resource properties.- Parameters:
name (str) -- The name of the DSC resource to manage, for example
WindowsFeatureorFile. This also serves as the state ID. Required.module_name (str) -- The name of the PowerShell module that contains the resource. For built-in resources use
PSDesiredStateConfiguration. Required.properties (dict) -- A dictionary of the desired resource properties. The required and optional keys vary by DSC resource. Required.
- Returns:
A standard Salt state return with
name,result,changes, andcommentkeys.resultvalues:True— no changes were needed, or changes were applied successfully.None— running in test mode and changes would be made.False— an error occurred or changes could not be verified.
- Return type:
CLI Example:
install_iis: dsc_resource.managed: - name: WindowsFeature - module_name: PSDesiredStateConfiguration - properties: Name: Web-Server Ensure: Present
write_hosts_entry: dsc_resource.managed: - name: File - module_name: PSDesiredStateConfiguration - properties: DestinationPath: C:\\Temp\\hello.txt Ensure: Present Contents: Hello from Salt
New in version 3008.1.