AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Add Windows Registry on Windows-like systems - Ansible module win_regedit — Video Tutorial
Learn how to use Ansible win_regedit module to add, change, or remove Windows registry key-values efficiently and accurately with simple Ansible code examples.
What You'll Learn
- How to Add Windows Registry key-value on Windows-like systems with Ansible?
- Ansible adds Windows Registry on Windows-like systems
- Parameters
- Links
- code
- execution
- idempotency
- before execution
- after execution
- Conclusion
Full Tutorial Content
How to Add Windows Registry key-value on Windows-like systems with Ansible?
Changing registry values manually can be time-consuming and error-prone.
Ansible includes built-in capabilities for managing individual key-value pairs in an idempotent way.
I'm going to show you a live Playbook and some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot
Ansible adds Windows Registry on Windows-like systems
- `ansible.windows.win_regedit`
- Get information about Windows registry keys
Let's talk about the Ansible module `win_regedit`.
The full name is `ansible.windows.win_regedit`, which means that is part of the collection of modules specialized to interact with Windows target host.
It's a module pretty stable and out for years and it works in Windows and Windows Server operating systems.
It adds, changes, or remove registry keys and values.
Parameters
- `path` string - The full registry key path including the hive to search for
- `name` string - Name of the registry entry in the path parameters.
- `type` string - `string` / `none` / `binary` / `dword` / `expandstring` / `multistring` / `qword`
- `data` string - Value of the registry entry
- `state` string - `present` / `absent`
The only mandatory parameter is "path" which is the full registry key path including the hive to search for.
Almost mandatory is also the "name" of the name of the registry entry in the path parameters.
Another important parameter is the "`type`" specify the datatype of the value: `string`, `dword`, `qword`, `binary`, `multistring`, etc. Some values could either be represented as a decimal number or a hex value. Multi-string values should be passed in as a list. Refer to the module manual for more details and examples.
Finally, we could specify the value of the registry entry in the "data" parameter.
Another useful parameter is the "`state`" to specify if we would like to add or modify ("present" option) or remove ("absent" option).
Links
- [ansible.windows.win_regedit](https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_regedit_module.html)
- [How to add, modify, or delete registry subkeys and values by using a .reg file](https://support.microsoft.com/en-us/topic/how-to-add-modify-or-delete-registry-subkeys-and-values-by-using-a-reg-file-9c7f37cf-a5e9-e1cd-c4fa-2a26218a1a23)
## Playbook
How to Add Windows Registry on Windows-like systems accessing the Windows Registry with Ansible Playbook.
Specifically, I'm going to create a Windows Registry key located in "HKEY_LOCAL_MACHINE\Software\Test".
code
```yaml
---
- name: windows registry add
hosts: all
vars:
mypath: 'HKLM:\Software\Test'
mykey: 'hello'
mytype: string
myvalue: 'world'
tasks:
- name: registry add key-value
ansible.windows.win_regedit:
path: "{{ mypath }}"
name: "{{ mykey }}"
type: "{{ mytype }}"
data: "{{ myvalue }}"
```
execution
```bash
ansible-pilot $ ansible-playbook -i virtualma
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 3 min
- Category: troubleshooting
Read the full written article: Add Windows Registry on Windows-like systems - Ansible module win_regedit
Related Video Tutorials
- Check .NET Framework Version on Windows with Ansible — Learn how to check the .NET Framework version on Windows systems with Ansible using the win_reg_stat module.
- Ansible win_regedit: Manage Windows Registry Keys & Values (Examples) — How to manage Windows Registry with Ansible win_regedit module. Create, modify, and remove registry keys and values with practical automation examples.
- Ansible win_file Module: Create Directory on Windows Hosts (Guide) — How to create directories on Windows with Ansible win_file module (ansible.windows.win_file). Set paths, manage folders, handle permissions.
- Ansible win_file Module: Create & Manage Files on Windows (Guide) — How to create and manage files on Windows with Ansible win_file module (ansible.windows.win_file). Create files, directories, symlinks on Windows.
- Ansible Windows Update: Rolling Updates with win_updates Module (Guide) — How to manage Windows Updates with Ansible win_updates module. Rolling updates, selective patching, reboot handling, and WSUS integration with playbook.
- Ansible Change Windows User Password: win_user Module (Examples) — How to change local Windows user passwords with Ansible win_user module. Reset passwords, set expiry policies, and manage credentials across Windows servers.