Built-in module reference

on this page

Modules: registry, service, file, directory, package, winget_package, choco_package, scoop_package, remove_appx_packages, shortcut, scheduled_task, user, power_plan, windows_feature, environment, firewall_rule, powershell, shell, reboot, wait.

Execution contract

Each module implements Check() and Apply(). Preflight calls Check() first:

  • No change needed: the task reports ok and Apply() does not run.
  • Change needed: Apply() runs and the task reports changed. Under preflight check, Apply() does not run and the task reports changed with the message would apply change (dry-run).

Task forms

Inline:

yaml
- name: Create content directory
  directory:
    path: "C:\\Exhibits\\Content"

Explicit:

yaml
- name: Create content directory
  module: directory
  params:
    path: "C:\\Exhibits\\Content"

Inline parameters are validated against the module schema before the run, and unknown parameters are errors. params in the explicit form is not schema-validated.

Platform and transport support

Every built-in module runs on local, ssh, and winrm targets. Every target must be Windows with Windows PowerShell. The local target requires a Windows controller.

Some operations cannot complete over WinRM; see WinRM session limitations.

Plugin modules run on every transport; see Execution model.

An unknown module name fails at plan time; see Plan-time checks.

WinRM session limitations

WinRM authenticates with Basic auth, so only local accounts work, and each operation runs under a non-interactive network logon. These operations fail in that session:

OperationFailure
windows_feature enable or disableThe symbolic link cannot be followed because its type is disabled. DISM cannot follow component store links under a network logon. Reading feature state works.
remove_appx_packages with all_users or both scopeRemove-AppxPackage -AllUsers fails with HRESULT 0x80073D19, An error occurred because a user was logged off.
Output streamingOutput arrives in one batch when the command ends, not line by line.

WinRM has no CredSSP option; see Would CredSSP help?. Workarounds:

  • Run on the machine with the local target or a staged bundle.
  • Run from an interactive or elevated context, such as a scheduled task.
  • For streaming output, use SSH.

Modules

registry

Manages a registry key and its values.

ParameterTypeRequiredDefaultDescription
pathstringyesKey path. Accepts HKLM, HKCU, HKCR, HKU, and HKCC prefixes, with or without :, and the HKEY_* names
valueslistnoValue specs
ensurepresent, absentnopresentabsent deletes the key and its subkeys
userstringnoLocal user whose HKCU hive to edit; requires an HKCU path

Registry value spec

FieldTypeRequiredDefaultDescription
namestringyesValue name
typestring, expand_string, dword, qword, binary, multi_stringnoinferred from dataValue type
dataanywith ensure: present and no patchValue data
patchlistnoByte patches for an existing binary value; each entry has offset (integer) and data (byte, 0-255). Cannot be combined with data
ensurepresent, absentnopresentDesired value state

Without type, a string is string, an integer or boolean is dword, a list of strings is multi_string, and a list of numbers is binary.

With user, the user’s profile hive is loaded for the task and unloaded after it. Errors:

  • user <name> was not found on this machine
  • user <name> has no profile on this machine; sign in once to create it
  • registry: user can only be used with HKCU/HKEY_CURRENT_USER paths
yaml
- name: Enable taskbar auto-hide
  registry:
    path: 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3'
    values:
      - name: Settings
        type: binary
        patch:
          - offset: 8
            data: 3

service

Manages an existing Windows service.

ParameterTypeRequiredDefaultDescription
namestringyesService name
staterunning, stopped, disablednodisabled stops the service and sets startup to disabled, and ignores startup_type
startup_typeautomatic, manual, disablednoStartup type

Fails with service not found: <name> when the service does not exist.

yaml
- name: Start Windows Time
  service:
    name: W32Time
    state: running
    startup_type: automatic

file

Manages a file on the target.

ParameterTypeRequiredDefaultDescription
deststringyesPath on the target
srcstringnoPath on the controller to copy
contentstringnoFile content; accepts secret:<name>
content_templatestringnoFile content rendered as a template; accepts secret("name")
ensurepresent, absentnopresentDesired state
  • Set at most one of src, content, and content_template.
  • Check() compares SHA-256 hashes of the source and the target file.
  • content and content_template are written as UTF-8 without a byte order mark. Parent directories are created.
  • With none of the three set, a missing file is created empty and an existing file is left unchanged.
  • content_template renders after all other parameters; see Secrets in templates.
yaml
- name: Write app config
  file:
    dest: "C:\\Exhibits\\app.ini"
    content_template: |
      username={{ vars.app_user }}
      password={{ secret("app-password") }}

directory

Manages a directory.

ParameterTypeRequiredDefaultDescription
pathstringyesDirectory path
ensurepresent, absentnopresentpresent creates parent directories; absent deletes the directory and its contents
yaml
- name: Create content directory
  directory:
    path: "C:\\Exhibits\\Content"

package

Installs or removes MSI and EXE packages.

ParameterTypeRequiredDescription
packageslistyesPackage entries

Each entry:

FieldTypeRequiredDefaultDescription
product_idstringyesProduct code, matched against the uninstall registry keys
sourcestringwith ensure: presentInstaller path on the controller; copied to a temporary directory on the target before install
argsstring[]noExtra installer arguments
ensurepresent, absentnopresentDesired state
  • An .msi source runs msiexec /i <source> /qn /norestart <args>. Any other source runs directly with args.
  • absent runs msiexec /x <product_id> /qn /norestart.
  • A non-zero exit code fails the task.
yaml
- name: Install packages
  package:
    packages:
      - product_id: "{D5E71B88-9A6C-4B6B-89C0-123456789ABC}"
        source: "C:\\Installers\\app.msi"
      - product_id: "{0F1E2D3C-4B5A-6978-8796-A5B4C3D2E1F0}"
        ensure: absent

winget_package

Installs or removes packages with winget.

ParameterTypeRequiredDescription
packageslistyesPackage entries

Each entry:

FieldTypeRequiredDefaultDescription
idstringyeswinget package ID, matched exactly
versionstringnoExact version to install
sourcestringnowinget source name
argsstring[]noExtra winget arguments for this package
scopemachine, usernomachineInstall scope
ensurepresent, absentnopresentDesired state
  • Without version, an installed package satisfies present. With version, the installed version must match.
  • Each id may appear once, compared case-insensitively. WinGet can’t install two versions of one package side by side.
  • Installs run winget install --id <id> --exact --silent --scope <scope> with agreements accepted. Removals run winget uninstall --id <id> --exact.
  • After making changes, the task reads installed packages again and fails if any changed entry still isn’t in its desired state. WinGet sometimes reports a successful uninstall of a portable package that it didn’t remove.
  • winget runs as the transport account. If winget.exe or the winget source isn’t registered for that account, the task fails and asks for a preflight/winget task first. This happens on editions without WinGet, such as Windows IoT Enterprise LTSC, and for accounts that have never signed in interactively.
yaml
- name: Install tools
  winget_package:
    packages:
      - id: Microsoft.VisualStudioCode
        version: "1.85.0"
      - id: Microsoft.VisualStudio.2022.Community
        args: ["--override", "--quiet --wait --norestart"]
      - id: OldApp
        ensure: absent

choco_package

Installs or removes packages with Chocolatey.

ParameterTypeRequiredDescription
packageslistyesPackage entries

Each entry:

FieldTypeRequiredDefaultDescription
idstringyesChocolatey package ID, matched case-insensitively
versionstringnoExact version to install
sourcestringnoSource name or URL to install from
paramsstringnoPackage parameters, passed as --params
argsstring[]noExtra choco arguments for this package
ensurepresent, absentnopresentDesired state
  • Without version, an installed package satisfies present. With version, the installed version must match. Versions compare after dropping trailing zero parts, so 1.6 matches 1.6.0.
  • Each id may appear once. Chocolatey keeps one version of each package.
  • Installs run choco install <id> -y --no-progress. With version, the task runs choco upgrade <id> --version <version> --allow-downgrade -y --no-progress instead, which installs, upgrades, or downgrades. Removals run choco uninstall <id> -y --no-progress. source, params, and args apply to installs and upgrades; args also applies to removals.
  • Exit codes 0, 1605, 1614, 1641, and 3010 succeed. For 1641 and 3010 the task prints that a reboot is required; add a reboot task if the package needs one.
  • After making changes, the task reads installed packages again and fails if any changed entry still isn’t in its desired state.
  • Chocolatey installs machine-wide, so there is no scope.
  • The task runs choco.exe from the machine’s ChocolateyInstall directory. If Chocolatey isn’t installed, the task fails and asks for a preflight/chocolatey task first.
  • Double quotes inside params are removed before Chocolatey sees them. Quote values with single quotes, such as /Dir:'C:\Program Files\App'.
  • Requires Chocolatey 2.0 or later. The task fails on 1.x, and when it can’t read the Chocolatey version, because 1.x choco list searches the remote source instead of listing installed packages.
  • Known limitation: single quotes inside a params value aren’t escaped, so a value can’t contain a literal '.
yaml
- name: Install tools
  choco_package:
    packages:
      - id: 7zip
      - id: jq
        version: "1.7.1"
      - id: vlc
        params: "/Language:en"
      - id: oldapp
        ensure: absent

scoop_package

Installs or removes Scoop apps for the transport account.

ParameterTypeRequiredDescription
packageslistyesApp entries

Each entry:

FieldTypeRequiredDefaultDescription
idstringyesApp name, optionally with its bucket, such as extras/vscode. Matched case-insensitively, without the bucket
versionstringnoExact version to install
activeboolnotrue for a versioned app listed onceMake this version current
argsstring[]noExtra scoop arguments for this app
ensurepresent, absentnopresentDesired state
  • Without version, an installed app satisfies present. With version, that version must be installed, and if the entry is active, current.
  • Scoop keeps several versions of an app side by side. To keep more than one, list the app once per version and set active: true on exactly one entry. Older versions stay installed until they are removed with ensure: absent.
  • ensure: absent removes every version, so it can’t be combined with version.
  • Installs run scoop install <id> or scoop install <id>@<version>, then scoop reset <app>@<version> when the active version isn’t current. Removals run scoop uninstall <app>.
  • Pinned versions need the app’s bucket to be a git clone. preflight/scoop sets that up.
  • Scoop exits 0 for some failures. The task fails when Scoop prints an error, and after making changes it reads installed apps again and fails if any changed entry still isn’t in its desired state.
  • Apps install for the transport account only; there is no machine-wide scope. To install for another account, connect as that account.
  • The task finds Scoop through the user-scope SCOOP environment variable, or %USERPROFILE%\scoop. A machine-scope SCOOP isn’t supported.
  • If Scoop isn’t installed for the transport account, the task fails and asks for a preflight/scoop task first.
yaml
- name: Node toolchain
  scoop_package:
    packages:
      - id: nodejs
        version: "22.11.0"
        active: true
      - id: nodejs
        version: "20.18.0"
      - id: versions/python310

remove_appx_packages

Removes AppX packages.

ParameterTypeRequiredDescription
packageslistyesPackage entries

Each entry:

FieldTypeRequiredDefaultDescription
namestringyesPackage name; accepts * wildcards
scopecurrent_user, all_users, provisioned, bothnobothboth covers all users and provisioned packages
ensureabsentnoDesired state
  • Packages that Windows marks NonRemovable are ignored.
  • A failed provisioned-package removal prints a warning and does not fail the task.
yaml
- name: Remove preinstalled apps
  remove_appx_packages:
    packages:
      - name: Microsoft.Xbox*
      - name: Microsoft.BingNews
        scope: provisioned

shortcut

Creates or updates a .lnk shortcut.

ParameterTypeRequiredDescription
destinationstringyes.lnk path
targetstringnoTarget path
argsstringnoArguments
iconstringnoIcon location

Environment variables in destination, target, and icon are expanded on the target. Parent directories are created.

yaml
- name: Add kiosk shortcut
  shortcut:
    destination: "%PUBLIC%\\Desktop\\Kiosk.lnk"
    target: "C:\\Exhibits\\kiosk.exe"
    args: "--fullscreen"

scheduled_task

Manages a scheduled task.

ParameterTypeRequiredDefaultDescription
namestringyesTask name
executestringunless ensure: absentExecutable
pathstringno\Task folder, such as \Preflight\; created when missing
argumentsstringnoArguments
working_dirstringnoWorking directory
triggerstartup, onlogon, daily, oncenostartupTrigger
start_atstringwith trigger: once03:00 for dailyStart time
delaystringnoTrigger delay for startup and onlogon: an ISO 8601 duration (PT30S) or a Go duration (30s)
run_asstringnoRun-as user. SYSTEM, LOCALSERVICE, and NETWORKSERVICE run as service accounts; other users use an interactive logon
run_levelleast, highestnoleastPrivilege level
enabledboolnotrueEnabled state
ensurepresent, absentnopresentDesired state

Apply() unregisters and re-registers the task.

yaml
- name: Launch kiosk at logon
  scheduled_task:
    path: \Preflight\
    name: Kiosk
    execute: "C:\\Exhibits\\kiosk.exe"
    trigger: onlogon
    delay: 30s
    run_level: highest

user

Manages a local user.

ParameterTypeRequiredDefaultDescription
namestringyesUser name
passwordstringnoPassword; accepts secret:<name>
groupsstring[]noLocal groups to add the user to
ensurepresent, absentnopresentDesired state
  • A new user without password is created with no password. For an existing user, omitting password leaves it unchanged.
  • groups adds memberships and removes none.
yaml
- name: Create exhibit user
  user:
    name: exhibit
    password: secret:exhibit-password
    groups: [Users]

power_plan

Manages a named power scheme.

ParameterTypeRequiredDefaultDescription
namestringyesScheme name
basestringnobalancedScheme to copy when creating: balanced, high_performance, power_saver, or a GUID
activateboolnotrueActivate the scheme
settingslistnoSetting overrides
ensurepresent, absentnopresentabsent deletes the scheme, activating Balanced first if the scheme is active

Each settings entry:

FieldTypeRequiredDescription
subgroupstringyesSubgroup alias or GUID
settingstringyesSetting alias or GUID
ac_valueintegernoValue on AC power
dc_valueintegernoValue on battery
yaml
- name: Never sleep
  power_plan:
    name: Exhibit
    base: high_performance
    settings:
      - subgroup: SUB_SLEEP
        setting: STANDBYIDLE
        ac_value: 0
        dc_value: 0

windows_feature

Enables or disables a Windows optional feature.

ParameterTypeRequiredDefaultDescription
namestringyesFeature name
ensurepresent, absentnopresentDesired state
  • Changes do not restart Windows. Enabling uses -LimitAccess, so Windows Update is not contacted.
  • Fails with windows_feature not found: <name> when the feature does not exist.
  • Changes fail over WinRM; see WinRM session limitations.
yaml
- name: Enable Telnet client
  windows_feature:
    name: TelnetClient

environment

Manages an environment variable.

ParameterTypeRequiredDefaultDescription
namestringyesVariable name
valuestringnoValue
scopemachine, usernomachineuser without user targets the connecting account
userstringnoLocal user whose environment to edit; requires scope: user. The profile hive is loaded for the task
ensurepresent, absentnopresentDesired state

user without scope: user fails with environment: user requires scope: user.

yaml
- name: Set content root
  environment:
    name: EXHIBIT_CONTENT
    value: "C:\\Exhibits\\Content"

firewall_rule

Manages a Windows Firewall rule, matched by display name.

ParameterTypeRequiredDefaultDescription
namestringyesRule display name
directioninbound, outboundnoinboundDirection
actionallow, blocknoallowAction
protocoltcp, udp, anynotcpProtocol
portsinteger, string, or listnoLocal ports; a list is passed as an array. Requires protocol tcp or udp
ensurepresent, absentnopresentDesired state
yaml
- name: Allow kiosk control port
  firewall_rule:
    name: Kiosk control
    direction: inbound
    action: allow
    protocol: tcp
    ports: 8080

Defaults are enforced on existing rules too: an existing rule with protocol Any is changed to TCP unless the task sets protocol: any.

powershell

Runs a PowerShell script in a new session.

ParameterTypeRequiredDescription
scriptstringone of script or fileInline script
filestringone of script or fileScript path on the controller; its contents run on the target
argsstring[]noArguments for file
check_scriptstringnoScript that decides whether a change is needed
createsstringnoPath that, when it exists, means no change is needed
working_dirstringnoWorking directory; relative creates paths resolve from it
envobjectnoProcess environment variables for the script, check_script, and creates
  • Without check_script or creates, the script runs every time.
  • check_script takes precedence over creates. It must output a boolean, where true means a change is needed, or an object with needs_change and an optional message.
yaml
- name: Register kiosk app
  powershell:
    check_script: |
      -not (Test-Path 'HKLM:\SOFTWARE\Kiosk')
    script: |
      New-Item -Path 'HKLM:\SOFTWARE\Kiosk' -Force | Out-Null

shell

Runs a command with the PowerShell call operator: & <cmd> <args>.

ParameterTypeRequiredDescription
cmdstringyesCommand or executable path
argsstring[]noArguments
createsstringnoPath that, when it exists, means no change is needed
working_dirstringnoWorking directory; relative creates paths resolve from it
envobjectnoEnvironment variables set for the command; restored afterward
  • Without creates, the command runs every time.
  • A non-zero exit code fails the task with <cmd> exited with code <code>.
yaml
- name: Register license
  shell:
    cmd: "C:\\Exhibits\\license.exe"
    args: ["--register"]
    creates: "C:\\Exhibits\\license.dat"

reboot

Schedules a restart with shutdown /r /t <timeout>.

ParameterTypeRequiredDefaultDescription
timeoutintegerno300Seconds before the restart
  • The task always reports a change.
  • Preflight does not wait for the target to restart or reconnect. Tasks after reboot run while the restart is pending.
yaml
- name: Restart in one minute
  reboot:
    timeout: 60

wait

Waits until a condition is true.

ParameterTypeRequiredDefaultDescription
conditionport_open, file_exists, service_runningyesCondition
targetstringyesCondition target; see below
timeoutstringno5mGo duration, such as 30s or 1h
conditiontargetTrue when
port_openhost:portA TCP connection succeeds within 2 seconds
file_existsPathThe path exists
service_runningService nameThe service status is Running

The condition is checked every 5 seconds, and the task fails with wait: timeout after <timeout> waiting for condition "<condition>" on "<target>" when the timeout passes. A condition that is already true reports no change.

yaml
- name: Wait for the content server
  wait:
    condition: port_open
    target: "localhost:8080"
    timeout: 2m