ansible.windows.dsc3 module – Sets or checks DSC v3 configuration state
Note
This module is part of the ansible.windows collection (version 3.9.1).
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install ansible.windows.
To use it in a playbook, specify: ansible.windows.dsc3.
New in ansible.windows 3.4.0
Synopsis
Calls
dsc config setusingconfigorconfig_fileas the configuration document.The module is tested against Microsoft DSC 3.3. Older 3.x releases work as long as the options that map to newer DSC features, such as
ignore_settings_file, are not used.By default
dscmust be discoverable through thePATHenvironment variable, whichdscitself also uses to discover resources. Useexecutableto run a specificdsc.exeandresource_pathto control where resources are discovered.
Note
This module has a corresponding action plugin.
Parameters
Parameter |
Comments |
|---|---|
Set the specified path as the working directory of the When |
|
The DSC configuration document to set or test. See https://learn.microsoft.com/en-us/powershell/dsc/concepts/configuration-documents/overview?view=dsc-3.0 for an overview of how to author a configuration document. The One of |
|
Path to DSC configuration document either on the control node or the target host. The This corresponds to the One of |
|
Path to the By default Default: |
|
Ignore the DSC settings and policy files when running the command. This corresponds to the Choices:
|
|
Runtime parameter values. This corresponds to the Can be combined with |
|
Path on the target host to a JSON or YAML file with runtime parameter values. The file must contain a top-level This corresponds to the |
|
Whether the provided If A local Choices:
|
|
List of directories When set, |
|
Path to the root of the operating system to target when it is not the running one, for example an offline image. This corresponds to the |
|
Specify level of tracing output, which is returned in Messages of level This corresponds to the Choices:
|
Notes
Note
The
dscprocess runs as the user Ansible connects with. If that user does not have the rights a resource needs,becomemay be able to help.A configuration document can require a security context through the
securityContextkey of its top-leveldirectivesproperty, with the valueelevatedorrestricted.dscchecks this before it invokes any resource and the task fails with exit code 2 when thedscprocess does not run in that context.In check mode the module runs
dsc config set --what-if, which reports the changes that would be made without changing the system. This requires DSC 3.1.0 or later. Resources without native what-if support are simulated from their test operation, but group resources such asMicrosoft.DSC/GroupandMicrosoft.DSC/Includeand resources that declareimplementsPretestdo not support what-if and fail the task with exit code 2.The changed status is derived from the
changedPropertiesof each resource. The nested results of group resources such asMicrosoft.DSC/GroupandMicrosoft.DSC/Includeare walked recursively so a group is only reported as changed when one of its resources changed.When run with diff mode, the diff lists every resource with its name and type. Resources that changed also include the properties that changed and group resources contain a nested
resourceslist.Warnings emitted by
dscare reported as Ansible warnings and the last error emitted bydscis included inmsgwhen the command fails.
See Also
See also
- ansible.windows.win_dsc
Invokes a PowerShell DSC configuration.
- DSC configuration document schema
Reference documentation for configuration documents, including the
directivesproperty.
Examples
- name: Install DSC3 using WinGet
ansible.windows.win_command:
argv:
- winget
- install
- --id=Microsoft.DSC
- --exact
- --source=winget
- --scope=machine
- --accept-package-agreements
- --accept-source-agreements
- --disable-interactivity
creates: '{{ ansible_env.ProgramFiles }}\WinGet\Links\dsc.exe'
- name: Install .NET Framework SDK from winget
ansible.windows.dsc3:
config:
resources:
- name: Install .NET Framework
type: Microsoft.WinGet/Package
properties:
id: Microsoft.DotNet.Framework.DeveloperPack_4
source: winget
- name: Install Visual Studio Build Tools
ansible.windows.dsc3:
config:
resources:
- name: Install Visual Studio
type: Microsoft.WinGet/Package
properties:
id: Microsoft.VisualStudio.2022.{{ vs_product }}
source: winget
- name: Install Visual Studio components
type: Microsoft.VisualStudio.DSC/VSComponents
properties:
productId: Microsoft.VisualStudio.Product.{{ vs_product }}
channelId: VisualStudio.17.Release
components:
- Microsoft.VisualStudio.Component.VC.14.44.17.14.x86.x64
- Microsoft.VisualStudio.Component.Windows11SDK.22621
vars:
vs_product: BuildTools
- name: Require an elevated session and DSC 3.3 or later before configuring the registry
ansible.windows.dsc3:
config:
directives:
securityContext: elevated
version: '>=3.3.0'
resources:
- name: Example key
type: Microsoft.Windows/Registry
properties:
keyPath: HKLM\Software\Example
_exist: true
register: dsc_result
- name: Reboot when a resource requires it
ansible.windows.win_reboot:
when: dsc_result.reboot_required
- name: Run a specific dsc executable with additional resource directories
ansible.windows.dsc3:
executable: '{{ ansible_env.ProgramFiles }}\WinGet\Links\dsc.exe'
resource_path:
- '{{ ansible_env.ProgramFiles }}\DSC'
- C:\DscResources
config:
resources:
- name: Custom resource
type: Contoso/Example
properties:
enabled: true
- name: Include a configuration document from a directory on the target
ansible.windows.dsc3:
chdir: C:\dsc\configs
config:
resources:
- name: Base configuration
type: Microsoft.DSC/Include
properties:
configurationFile: base.dsc.config.yaml
parametersFile: base.parameters.yaml
- name: Apply a configuration with parameters from a file and the playbook
ansible.windows.dsc3:
config_file: C:\dsc\configs\web.dsc.config.yaml
remote_config_file: true
parameters_file: C:\dsc\configs\web.parameters.yaml
parameters:
siteName: '{{ inventory_hostname }}'
- name: Preview the changes DSC would make without applying them
ansible.windows.dsc3:
config_file: files/baseline.dsc.config.yaml
check_mode: true
diff: true
register: dsc_preview
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
Not returned by DSC releases before 3.2.0. Returned: success Sample: |
|
Error message when Contains the exit code with its meaning and the last error message emitted by Returned: failure Sample: |
|
Exit code of Returned: always |
|
Whether a resource reported that the system needs to be restarted to complete the configuration. Returned: success Sample: |
|
The restart requirements reported by the resources, aggregated from Each entry contains a Returned: success Sample: |
|
Result object returned by See https://learn.microsoft.com/en-us/powershell/dsc/reference/schemas/outputs/config/set?view=dsc-3.0 for the schema of this object. Returned: success |
|
Details regarding the DSC execution such as the operation, the execution type, the timings, the security context and the restart requirements reported by resources. Returned by DSC 3.2.0 and later, older releases only return Returned: success |
|
Details regarding the DSC execution under the Since DSC 3.2.0 this is a deprecated copy of Returned: success |
|
List of results from each resource that were configured. The schema of each item depends on the resource’s type. Returned: success |
|
The security context Returned: success Sample: |
|
Raw output of Returned: always |
|
Logging and tracing messages from May be empty if no messages were emitted at the levels allowed by Returned: always |