### Install Collection from Ansible Galaxy Source: https://github.com/ansible-collections/ansible.windows/blob/main/README.md Install the Windows collection using the ansible-galaxy CLI. This command fetches and installs the latest version of the collection. ```bash ansible-galaxy collection install ansible.windows ``` -------------------------------- ### Install ansible.windows Collection Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Install the collection from Ansible Galaxy. Declare it as a dependency in requirements.yml for project-specific installations. ```yaml collections: - name: ansible.windows version: ">=3.5.0" ``` ```bash ansible-galaxy collection install ansible.windows # or from requirements file ansible-galaxy collection install -r requirements.yml ``` -------------------------------- ### ansible.windows.setup: Gather Windows Host Facts Source: https://context7.com/ansible-collections/ansible.windows/llms.txt The setup module automatically gathers facts about the remote Windows host, including OS details, network information, and hardware specifications. It can be customized to gather specific subsets of facts, set a timeout, skip certain subsets, or load custom facts from a specified path. ```yaml - name: Collect Windows facts hosts: windows_hosts tasks: - name: Gather all facts ansible.windows.setup: - name: Only gather network and OS facts ansible.windows.setup: gather_subset: - network - hardware gather_timeout: 30 - name: Skip collection of certain subsets ansible.windows.setup: gather_subset: - "!facter" - "!ohai" - name: Load custom facts from a directory ansible.windows.setup: fact_path: C:\\custom_facts - name: Print key facts ansible.builtin.debug: msg: > OS: {{ ansible_os_name }} Version: {{ ansible_os_version }} Hostname: {{ ansible_hostname }} IPs: {{ ansible_ip_addresses }} ``` -------------------------------- ### Install Windows Updates with Ansible Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use `win_updates` to search, download, and install Windows Updates. Supports category filtering, reboot control, and update server selection. Can be run asynchronously. ```yaml - name: Patch Windows hosts hosts: windows_hosts tasks: # Install all critical + security + rollup updates, reboot as needed - name: Fully patch the host ansible.windows.win_updates: category_names: '*' reboot: true reboot_timeout: 3600 # Install only security and critical updates without rebooting - name: Install security updates (no auto reboot) ansible.windows.win_updates: category_names: - SecurityUpdates - CriticalUpdates register: update_result - name: Show update count ansible.builtin.debug: msg: "Installed {{ update_result.installed_update_count }} updates" # Manual reboot if required - name: Reboot if updates require it ansible.windows.win_reboot: reboot_timeout: 1800 when: update_result.reboot_required # Dry-run — search only, do not install - name: List available updates ansible.windows.win_updates: state: searched category_names: SecurityUpdates log_path: C:\\ansible_updates.txt register: available_updates - name: Print pending updates ansible.builtin.debug: msg: "{{ available_updates.updates | dict2items | map(attribute='value.title') | list }}" # Whitelist specific KBs only - name: Apply only a specific KB ansible.windows.win_updates: accept_list: - KB5034441 reboot: false # Exclude a specific update by KB - name: Install all security updates except a known problematic one ansible.windows.win_updates: category_names: - SecurityUpdates reject_list: - KB5034441 ``` -------------------------------- ### ansible.windows.setup — Gather Windows host facts Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Automatically invoked at the start of every play (when `gather_facts: true`) to populate `ansible_*` variables about the remote Windows host — OS version, IP addresses, CPU, memory, disks, environment variables, and more. Can be called explicitly to restrict the subset collected or to load custom local facts from `.ps1`/`.json` files. ```APIDOC ## ansible.windows.setup ### Description Automatically invoked at the start of every play (when `gather_facts: true`) to populate `ansible_*` variables about the remote Windows host — OS version, IP addresses, CPU, memory, disks, environment variables, and more. Can be called explicitly to restrict the subset collected or to load custom local facts from `.ps1`/`.json` files. ### Method `ansible.windows.setup` ### Parameters #### Parameters - **gather_subset** (list) - Optional - A list of fact subsets to gather. Can include negation (e.g., `!facter`). - **gather_timeout** (int) - Optional - The timeout in seconds for gathering facts. - **fact_path** (string) - Optional - Path to a directory containing custom facts (e.g., `.ps1`/`.json` files). ### Request Example ```yaml - name: Gather all facts ansible.windows.setup: - name: Only gather network and OS facts ansible.windows.setup: gather_subset: - network - hardware gather_timeout: 30 - name: Skip collection of certain subsets ansible.windows.setup: gather_subset: - "!facter" - "!ohai" - name: Load custom facts from a directory ansible.windows.setup: fact_path: C:\custom_facts ``` ### Response #### Success Response - **ansible_os_name** (string) - The name of the operating system. - **ansible_os_version** (string) - The version of the operating system. - **ansible_hostname** (string) - The hostname of the Windows machine. - **ansible_ip_addresses** (list) - A list of IP addresses configured on the host. #### Response Example ```yaml OS: Microsoft Windows Server 2019 Standard Version: 10.0.17763 Hostname: WIN-SERVER IPs: ['192.168.1.100', 'fe80::a00:27ff:fe4f:6f7a'] ``` ``` -------------------------------- ### Manage Windows Services with win_service Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use this module to create, modify, start, stop, restart, pause, and remove Windows services. It supports various configurations including startup types, account assignments, failure actions, and dependencies. ```yaml - name: Manage Windows services hosts: windows_hosts tasks: # Ensure a built-in service is running and set to auto-start - name: Start the Print Spooler with auto start ansible.windows.win_service: name: spooler state: started start_mode: auto # Create a new service - name: Install MyApp as a Windows service ansible.windows.win_service: name: myapp path: C:\App\myapp.exe display_name: My Application Service description: Serves the MyApp REST API state: started start_mode: auto username: NT AUTHORITY\NetworkService # Run as a domain service account - name: Set service log-on account to a domain user ansible.windows.win_service: name: myapp username: DOMAIN\svc_myapp password: "{{ vault_svc_myapp_password }}" state: restarted # Configure failure actions - name: Set failure recovery for myapp (restart → restart → reboot) ansible.windows.win_service: name: myapp failure_actions: - type: restart delay_ms: 5000 - type: restart delay_ms: 10000 - type: reboot failure_reboot_msg: "myapp failed 3 times — rebooting" failure_reset_period_sec: 3600 # Ensure WinRM starts after other services settle (delayed auto) - name: Set WinRM to delayed auto start ansible.windows.win_service: name: WinRM start_mode: delayed # Remove a service - name: Uninstall the legacy service ansible.windows.win_service: name: legacy_svc state: absent ``` -------------------------------- ### Manage Windows Features with win_feature Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use this module to install or uninstall Windows Server Roles and Features. It supports sub-features, management tools, and installation from a specified source. Not available on Windows client editions. ```yaml - name: Manage Windows Server features hosts: windows_servers tasks: # Install IIS with all sub-features and management tools - name: Install IIS Web Server role ansible.windows.win_feature: name: Web-Server state: present include_sub_features: true include_management_tools: true register: iis_install # Reboot if the feature installation requires it - name: Reboot if IIS install required it ansible.windows.win_reboot: when: iis_install.reboot_required # Install multiple features at once - name: Install .NET Framework and RSAT tools ansible.windows.win_feature: name: - NET-Framework-Core - RSAT-AD-PowerShell - RSAT-DNS-Server state: present # Install from a side-by-side source (offline/WSUS scenario) - name: Install .NET 3.5 from installation media ansible.windows.win_feature: name: NET-Framework-Core source: D:\sources\sxs state: present # Remove a feature - name: Remove Telnet client ansible.windows.win_feature: name: Telnet-Client state: absent ``` -------------------------------- ### ansible.windows.win_updates Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Searches, downloads, and installs Windows Updates by driving the Windows Update Agent. Supports category filtering, accept/reject lists, automatic rebooting, update server selection, and an optional log path. Can be run asynchronously. ```APIDOC ## ansible.windows.win_updates — Download and install Windows Updates Searches, downloads, and installs Windows Updates by driving the Windows Update Agent. Supports category filtering, accept/reject lists (KB number or title regex), automatic rebooting, update server selection (Windows Update vs WSUS), and an optional log path. Can be run asynchronously for long-running update cycles. ### Parameters * **category_names** (list) - List of update categories to install. Use '*' for all categories. * **reboot** (bool) - If true, the host will be rebooted if an update requires it. * **reboot_timeout** (int) - The maximum time in seconds to wait for the host to reboot. * **state** (str) - If 'searched', only search for updates without installing. * **accept_list** (list) - List of KB numbers or title regexes to explicitly accept. * **reject_list** (list) - List of KB numbers or title regexes to explicitly reject. * **log_path** (str) - Path to a file where update logs will be written. ### Examples ```yaml - name: Patch Windows hosts hosts: windows_hosts tasks: # Install all critical + security + rollup updates, reboot as needed - name: Fully patch the host ansible.windows.win_updates: category_names: '*' reboot: true reboot_timeout: 3600 # Install only security and critical updates without rebooting - name: Install security updates (no auto reboot) ansible.windows.win_updates: category_names: - SecurityUpdates - CriticalUpdates register: update_result - name: Show update count ansible.builtin.debug: msg: "Installed {{ update_result.installed_update_count }} updates" # Manual reboot if required - name: Reboot if updates require it ansible.windows.win_reboot: reboot_timeout: 1800 when: update_result.reboot_required # Dry-run — search only, do not install - name: List available updates ansible.windows.win_updates: state: searched category_names: SecurityUpdates log_path: C:\ansible_updates.txt register: available_updates - name: Print pending updates ansible.builtin.debug: msg: "{{ available_updates.updates | dict2items | map(attribute='value.title') | list }}" # Whitelist specific KBs only - name: Apply only a specific KB ansible.windows.win_updates: accept_list: - KB5034441 reboot: false # Exclude a specific update by KB - name: Install all security updates except a known problematic one ansible.windows.win_updates: category_names: - SecurityUpdates reject_list: - KB5034441 ``` ``` -------------------------------- ### Get File Information with ansible.windows.win_stat Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use `win_stat` to retrieve metadata about files and directories on Windows. It can check for existence, get size, checksums, timestamps, and attributes. Register the output to use the information in subsequent tasks. ```yaml - name: Inspect files on Windows hosts: windows_hosts tasks: - name: Check if config file exists ansible.windows.win_stat: path: C:\App\Config\app.config register: cfg_stat - name: Fail if config is missing ansible.builtin.fail: msg: "app.config not found — deployment incomplete" when: not cfg_stat.stat.exists - name: Get SHA-256 checksum ansible.windows.win_stat: path: C:\App\installer.msi get_checksum: true checksum_algorithm: sha256 register: installer_info - name: Show checksum ansible.builtin.debug: msg: "Installer SHA-256: {{ installer_info.stat.checksum }}" - name: Check directory size ansible.windows.win_stat: path: C:\inetpub\wwwroot get_size: true register: webroot - name: Warn if webroot is large ansible.builtin.debug: msg: "webroot is {{ (webroot.stat.size / 1048576) | round(1) }} MB" when: webroot.stat.size > 524288000 # stat keys: exists, isdir, isfile, islnk, size, checksum, # creationtime, lastaccesstime, lastwritetime, owner, attributes ``` -------------------------------- ### Manage files and directories on Windows using ansible.windows.win_file Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use win_file to create, touch, or remove files and directories on Windows. It can ensure directory trees exist, update file timestamps, or remove paths recursively. Does not manage ownership or ACLs. ```yaml - name: Create application data directories ansible.windows.win_file: path: C:\App\Data\Logs state: directory ``` ```yaml - name: Create or refresh a sentinel file ansible.windows.win_file: path: C:\App\Data\.initialized state: touch ``` ```yaml - name: Backdate a configuration file's modification time ansible.windows.win_file: path: C:\App\Config\legacy.ini state: file modification_time: "2023-01-15 09:00:00" access_time: "2023-01-15 09:00:00" ``` ```yaml - name: Clean up temporary installer ansible.windows.win_file: path: C:\Temp\setup.exe state: absent ``` ```yaml - name: Remove old build artifacts ansible.windows.win_file: path: C:\Build\old_artifacts state: absent ``` -------------------------------- ### Confirm PowerShell 7 is available using alternate executable Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Runs a script using 'pwsh.exe' (PowerShell 7) and asserts that the major version is 7. Demonstrates specifying an alternate executable and passing arguments to it. ```yaml - name: Confirm PowerShell 7 is available ansible.windows.win_powershell: script: $PSVersionTable.PSVersion.Major executable: pwsh.exe arguments: - -ExecutionPolicy - ByPass register: ps7_check failed_when: ps7_check.output[0] != 7 ``` -------------------------------- ### Include Collection in requirements.yml Source: https://github.com/ansible-collections/ansible.windows/blob/main/README.md Specify the ansible.windows collection in a requirements.yml file for automated installation. This is useful for managing collection dependencies in projects. ```yaml collections: - name: ansible.windows ``` -------------------------------- ### Get list of stopped services using inline script Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Executes an inline PowerShell script to retrieve a list of stopped services. The output is structured as a list of dictionaries. Set 'depth' to control the serialization depth of the output. ```yaml - name: Get list of stopped services ansible.windows.win_powershell: script: | Get-Service | Where-Object Status -eq Stopped | Select-Object -Property Name, DisplayName | ForEach-Object { $Ansible.Result += @($_) } depth: 3 register: stopped_svcs ``` -------------------------------- ### ansible.windows.win_file Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Manages the existence and timestamps of files and directories on Windows. Can create, touch, or remove files and directories. ```APIDOC ## ansible.windows.win_file — Create, touch, or remove files and directories Manages the existence and timestamps of files and directories on Windows. Creates empty files or full directory trees, touches existing files to update their timestamps, or recursively removes paths. Does **not** manage ownership or ACLs (use `win_acl` and `win_owner` for those). ### Parameters * **path** (str) - The path to the file or directory to manage. * **state** (str) - Desired state of the file or directory. Can be `directory`, `file`, `touch`, or `absent`. Defaults to `file`. * `directory`: Ensures a directory exists at the specified path. * `file`: Ensures a file exists at the specified path. If the path is a directory, it will be removed. * `touch`: Creates an empty file if it does not exist, or updates the access and modification times if it does. * `absent`: Ensures the file or directory at the specified path is removed. * **modification_time** (str) - Sets the modification time of the file. Accepts a date/time string or timestamp. * **access_time** (str) - Sets the access time of the file. Accepts a date/time string or timestamp. ### Examples ```yaml - name: Create application data directories ansible.windows.win_file: path: C:\App\Data\Logs state: directory - name: Create or refresh a sentinel file ansible.windows.win_file: path: C:\App\Data\.initialized state: touch - name: Backdate a configuration file's modification time ansible.windows.win_file: path: C:\App\Config\legacy.ini state: file modification_time: "2023-01-15 09:00:00" access_time: "2023-01-15 09:00:00" - name: Clean up temporary installer ansible.windows.win_file: path: C:\Temp\setup.exe state: absent - name: Remove old build artifacts ansible.windows.win_file: path: C:\Build\old_artifacts state: absent ``` ``` -------------------------------- ### Run Integration Tests with ansible-test Source: https://github.com/ansible-collections/ansible.windows/blob/main/README.md Run the collection's Windows integration tests using the ansible-test command with Docker. This verifies the functionality of the collection's modules and plugins in a Windows environment. ```bash ansible-test windows-integration --docker ``` -------------------------------- ### ansible.windows.win_copy Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Copies files or directories to Windows hosts over WinRM. Supports various options like backup, content-as-string, force, and copying as a different user. ```APIDOC ## ansible.windows.win_copy — Copy files to Windows hosts Copies files or directories from the Ansible control node (or between paths on the remote host) to Windows targets over WinRM. Supports backup-before-overwrite, content-as-string (no source file needed), force (overwrite only when changed), and `become`-based copying to alternate user directories. ### Parameters * **src** (str) - Path to the source file or directory on the Ansible control node or remote host. * **dest** (str) - Path on the destination Windows host where the file or directory will be copied. * **backup** (bool) - If true, creates a backup of the destination file before overwriting. Defaults to false. * **content** (str) - If specified, the content will be written directly to the destination file instead of copying from a source file. Mutually exclusive with `src`. * **force** (bool) - If true, overwrites the destination file only if the source file has changed. Defaults to true. * **remote_src** (bool) - If true, indicates that the `src` path is on the remote host, not the control node. Defaults to false. ### Examples ```yaml - name: Deploy config file ansible.windows.win_copy: src: files/app.config dest: C:\App\Config\ - name: Deploy config with backup ansible.windows.win_copy: src: files/app.config dest: C:\App\Config\app.config backup: true - name: Deploy default settings (first-run only) ansible.windows.win_copy: src: files/defaults.ini dest: C:\App\Config\settings.ini force: false - name: Write a connection string to a config file ansible.windows.win_copy: content: "Server=db01;Database=AppDB;User=app;Password={{ db_password }}" dest: C:\App\connection.config - name: Deploy web application files ansible.windows.win_copy: src: build/webapp/ dest: C:\inetpub\wwwroot\MyApp - name: Duplicate a config as a template ansible.windows.win_copy: src: C:\App\Config\app.config dest: C:\App\Config\app.config.template remote_src: true - name: Install per-user NuGet config ansible.windows.win_copy: src: NuGet.config dest: '%AppData%\NuGet\NuGet.config' vars: ansible_become_user: deploy_user ansible_become_password: "{{ deploy_password }}" ansible_remote_tmp: C:\shared_tmp ``` ``` -------------------------------- ### Run Sanity Tests with ansible-test Source: https://github.com/ansible-collections/ansible.windows/blob/main/README.md Execute the collection's sanity tests using the ansible-test command with Docker. This ensures the collection adheres to Ansible's coding standards. ```bash ansible-test sanity --docker ``` -------------------------------- ### Use the quote filter for safe argument building Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Demonstrates various uses of the ansible.windows.quote filter for different Windows command execution scenarios. ```yaml - name: Use the quote filter for safe argument building hosts: windows_hosts vars: user_input: "my file with spaces & special chars" install_props: INSTALLDIR: C:\Program Files\MyApp ALLUSERS: "1" tasks: # Quote a single value for win_command (C argv rules) - name: Pass user input to a command safely ansible.windows.win_command: argv: - C:\tools\processor.exe - "{{ user_input | ansible.windows.quote }}" # Quote for PowerShell - name: Build a PowerShell argument string ansible.windows.win_shell: cmd: "C:\\tools\\run.ps1 {{ user_input | ansible.windows.quote(shell='powershell') }}" # Quote for cmd.exe - name: Build a cmd.exe invocation ansible.windows.win_shell: cmd: "msbuild.exe {{ user_input | ansible.windows.quote(shell='cmd') }}" executable: C:\Windows\System32\cmd.exe # Quote a dict as MSI KEY=value pairs - name: Install an MSI with quoted properties ansible.windows.win_command: cmd: > msiexec.exe /i C:\Staging\app.msi /qn {{ install_props | ansible.windows.quote }} # Expands to: msiexec.exe /i C:\Staging\app.msi /qn INSTALLDIR="C:\Program Files\MyApp" ALLUSERS=1 # Quote a list of arguments - name: Pass multiple arguments safely ansible.windows.win_command: cmd: "C:\\tools\\multi.exe {{ ['arg one', 'arg two', '--flag'] | ansible.windows.quote }}" ``` -------------------------------- ### Execute commands directly on Windows with win_command Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use `win_command` to run executables directly on the remote Windows host. Arguments are not interpreted by a shell, making it more secure and predictable than `win_shell` when shell features are not required. It returns stdout, stderr, rc, and timing information. ```yaml - name: Capture current user ansible.windows.win_command: whoami register: whoami_out - name: Show who we are ansible.builtin.debug: msg: "Running as: {{ whoami_out.stdout | trim }}" ``` ```yaml - name: Run whoami with /all flag ansible.windows.win_command: cmd: whoami.exe /all ``` ```yaml - name: Run executable with spaces in path ansible.windows.win_command: argv: - C:\Program Files\MyApp\run.exe - --config - C:\App Config\settings.xml chdir: C:\Windows\TEMP ``` ```yaml - name: Run backup only if it has not been done ansible.windows.win_command: wbadmin start backup -backupTarget:D:\Backup\ args: creates: D:\Backup\ ``` ```yaml - name: Run a tool that emits Big5-encoded output ansible.windows.win_command: C:\tools\legacytool.exe args: output_encoding_override: big5 register: legacy_out ``` -------------------------------- ### ansible.windows.win_ping: Verify Windows Host Connectivity Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use the win_ping module to test WinRM connectivity to a Windows host. It returns 'pong' by default or a custom string specified by the 'data' parameter. This is a basic connectivity check. ```yaml - name: Verify all Windows hosts are reachable hosts: windows_hosts gather_facts: false tasks: - name: Ping the host ansible.windows.win_ping: register: ping_result - name: Show result ansible.builtin.debug: msg: "Host responded with: {{ ping_result.ping }}" # Expected output: "Host responded with: pong" - name: Use a custom return value ansible.windows.win_ping: data: alive register: custom_ping # custom_ping.ping == "alive" ``` -------------------------------- ### Copy files to Windows using ansible.windows.win_copy Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use win_copy to transfer files or directories to Windows targets. Supports renaming, backups, conditional copying, and setting content from variables. Can also copy directories or between remote paths. ```yaml - name: Deploy config file ansible.windows.win_copy: src: files/app.config dest: C:\App\Config\ ``` ```yaml - name: Deploy config with backup ansible.windows.win_copy: src: files/app.config dest: C:\App\Config\app.config backup: true register: copy_result ``` ```yaml - name: Deploy default settings (first-run only) ansible.windows.win_copy: src: files/defaults.ini dest: C:\App\Config\settings.ini force: false ``` ```yaml - name: Write a connection string to a config file ansible.windows.win_copy: content: "Server=db01;Database=AppDB;User=app;Password={{ db_password }}" dest: C:\App\connection.config ``` ```yaml - name: Deploy web application files ansible.windows.win_copy: src: build/webapp/ dest: C:\inetpub\wwwroot\MyApp ``` ```yaml - name: Duplicate a config as a template ansible.windows.win_copy: src: C:\App\Config\app.config dest: C:\App\Config\app.config.template remote_src: true ``` ```yaml - name: Install per-user NuGet config ansible.windows.win_copy: src: NuGet.config dest: '%AppData%\NuGet\NuGet.config' vars: ansible_become_user: deploy_user ansible_become_password: "{{ deploy_password }}" ansible_remote_tmp: C:\shared_tmp ``` -------------------------------- ### Ensure a directory exists with parameterized script Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Uses a parameterized PowerShell script to create a directory if it does not exist. Supports a 'Force' switch to overwrite existing items. The script signals if no change was made. ```yaml - name: Ensure a directory exists ansible.windows.win_powershell: script: | [CmdletBinding()] param([String]$Path, [Switch]$Force) if (-not (Test-Path $Path)) { New-Item -Path $Path -ItemType Directory -Force:$Force | Out-Null } else { $Ansible.Changed = $false } parameters: Path: C:\App\Data Force: true ``` -------------------------------- ### ansible.windows.win_regedit Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Manages Windows Registry keys and values, supporting various data types and hive loading. ```APIDOC ## ansible.windows.win_regedit — Add, change, or remove registry keys and values Manages Windows Registry keys and values. Supports all registry types (`string`, `dword`, `qword`, `binary`, `expandstring`, `multistring`, `none`) across all standard hives. Supports loading offline hive files (e.g., the default user profile hive) via the `hive` parameter. Full check-mode and diff support. ### Parameters - **path** (str) - Required - The registry key path. - **name** (str) - Optional - The name of the registry value. If omitted, the default value of the key is managed. - **data** (str, int, list, dict) - Optional - The data for the registry value. The type depends on the `type` parameter. - **type** (str) - Optional - The data type of the registry value. Supported types: `string`, `dword`, `qword`, `binary`, `expandstring`, `multistring`, `none`. Defaults to `string`. - **state** (str) - Optional - Whether the key or value should exist (`present`) or be absent (`absent`). Defaults to `present`. - **delete_key** (bool) - Optional - If set to `true`, the entire key and all its sub-keys/values will be deleted. Only applicable when `state` is `absent`. - **hive** (str) - Optional - The path to an offline hive file to load. This is useful for modifying user profiles or other offline hives. ### Example ```yaml - name: Manage Windows Registry hosts: windows_hosts tasks: # Create a registry key path - name: Ensure MyApp registry key exists ansible.windows.win_regedit: path: HKLM:\Software\MyCompany\MyApp # Set a string value - name: Set the application install path ansible.windows.win_regedit: path: HKLM:\Software\MyCompany\MyApp name: InstallPath data: C:\Program Files\MyApp type: string # Set a DWORD (integer) value - name: Enable debug mode (DWORD 1) ansible.windows.win_regedit: path: HKLM:\Software\MyCompany\MyApp name: DebugMode data: 1 type: dword # Set a multistring value - name: Configure allowed hosts list ansible.windows.win_regedit: path: HKLM:\Software\MyCompany\MyApp name: AllowedHosts data: - server1.example.com - server2.example.com type: multistring # Set binary data - name: Write a binary certificate thumbprint marker ansible.windows.win_regedit: path: HKLM:\Software\MyCompany\MyApp name: CertThumb data: [0xde, 0xad, 0xbe, 0xef] type: binary # Remove a specific value - name: Remove legacy registry value ansible.windows.win_regedit: path: HKLM:\Software\MyCompany\MyApp name: OldSetting state: absent # Delete an entire key and all its sub-keys/values - name: Uninstall MyApp registry entries ansible.windows.win_regedit: path: HKLM:\Software\MyCompany\MyApp state: absent delete_key: true # Modify the Default User profile (offline hive) - name: Disable IE first-run wizard for all new users ansible.windows.win_regedit: hive: C:\Users\Default\NTUSER.DAT path: HKLM:\ANSIBLE\Software\Microsoft\Internet Explorer\Main name: DisableFirstRunCustomize data: 1 type: dword ``` ``` -------------------------------- ### Apply DSC resources with win_dsc Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use the win_dsc module to apply PowerShell DSC resources idempotently on Windows servers. Options beyond resource_name and module_version are passed directly to the DSC resource. Requires PowerShell 5.x. ```yaml - name: Apply DSC resources with win_dsc hosts: windows_servers tasks: # Extract a zip archive using the Archive DSC resource - name: Unpack release archive ansible.windows.win_dsc: resource_name: Archive Ensure: Present Path: C:\\Staging\\release.zip Destination: C:\\App # Install a Windows feature via DSC - name: Install Telnet client via DSC ansible.windows.win_dsc: resource_name: WindowsFeature Name: Telnet-Client Ensure: Present # Manage a registry value via DSC - name: Set a registry DWORD via DSC ansible.windows.win_dsc: resource_name: Registry Ensure: Present Key: HKEY_LOCAL_MACHINE\Software\MyApp ValueName: Enabled ValueData: '1' ValueType: Dword # Run a DSC resource as a specific user (PsDscRunAsCredential) - name: Apply a user-context DSC resource ansible.windows.win_dsc: resource_name: Script GetScript: "return @{ Result = '' }" TestScript: "return $false" SetScript: "New-Item -Path C:\\user_data -ItemType Directory -Force" PsDscRunAsCredential_username: "{{ ansible_user }}" PsDscRunAsCredential_password: "{{ ansible_password }}" no_log: true ``` -------------------------------- ### Make HTTP requests from Windows hosts with win_uri Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Use the win_uri module to send HTTP/HTTPS/FTP requests from Windows target hosts. Supports various methods, authentication, and response handling. Ensure the 'status_code' parameter is set to expected values. ```yaml - name: Make HTTP requests from Windows hosts hosts: windows_hosts tasks: # Simple GET - name: Check health endpoint ansible.windows.win_uri: url: https://api.example.com/health status_code: [200] register: health # POST JSON data - name: Register the host with an inventory API ansible.windows.win_uri: url: https://inventory.example.com/api/hosts method: POST content_type: application/json body: '{"hostname": "{{ inventory_hostname }}", "role": "web"}' status_code: [200, 201] return_content: true register: register_result - name: Show response JSON ansible.builtin.debug: msg: "Registered with ID: {{ register_result.json.id }}" # Authenticated GET with Basic auth via web_request fragment options - name: Download a protected resource ansible.windows.win_uri: url: https://internal.corp/protected/file.zip method: GET dest: C:\\Temp\\file.zip url_username: svc_user url_password: "{{ vault_svc_password }}" force_basic_auth: true # HEAD request to check if a resource exists - name: Confirm artifact exists before download ansible.windows.win_uri: url: https://artifacts.example.com/releases/app-2.0.msi method: HEAD status_code: [200] ``` -------------------------------- ### ansible.windows.win_uri Source: https://context7.com/ansible-collections/ansible.windows/llms.txt Sends HTTP/HTTPS/FTP requests from the Windows target host. Supports various methods, authentication, and response handling. ```APIDOC ## ansible.windows.win_uri — Interact with HTTP/HTTPS/FTP web services Sends HTTP/HTTPS/FTP requests from the Windows target host. Supports all HTTP methods, custom headers, authentication (Basic, Digest, WSSE, certificate), request bodies, response body capture (including JSON parsing), and saving responses to files. ### Simple GET ```yaml - name: Check health endpoint ansible.windows.win_uri: url: https://api.example.com/health status_code: [200] register: health ``` ### POST JSON data ```yaml - name: Register the host with an inventory API ansible.windows.win_uri: url: https://inventory.example.com/api/hosts method: POST content_type: application/json body: '{"hostname": "{{ inventory_hostname }}", "role": "web"}' status_code: [200, 201] return_content: true register: register_result - name: Show response JSON ansible.builtin.debug: msg: "Registered with ID: {{ register_result.json.id }}" ``` ### Authenticated GET with Basic auth ```yaml - name: Download a protected resource ansible.windows.win_uri: url: https://internal.corp/protected/file.zip method: GET dest: C:\Temp\file.zip url_username: svc_user url_password: "{{ vault_svc_password }}" force_basic_auth: true ``` ### HEAD request ```yaml - name: Confirm artifact exists before download ansible.windows.win_uri: url: https://artifacts.example.com/releases/app-2.0.msi method: HEAD status_code: [200] ``` ```