ansible.windows.win_regedit 模块 – 添加、更改或删除注册表键和值
注意
此模块是 ansible.windows 集合 (版本 2.5.0) 的一部分。
如果您使用的是 ansible
包,则可能已安装此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install ansible.windows
。
要在 playbook 中使用它,请指定:ansible.windows.win_regedit
。
概要
添加、修改或删除注册表键和值。
维基百科上关于 Windows 注册表的更多信息 https://en.wikipedia.org/wiki/Windows_Registry。
参数
参数 |
注释 |
---|---|
如果未指定,则该属性的值对于相应的 二进制和 None 数据应以 yaml 字节数组或逗号分隔的十六进制值表示。 一种简单的方法是运行 在导出的文件中,二进制值将类似于 DWORD 和 QWORD 值应表示为十进制数或十六进制值。 多字符串值应作为列表传递。 有关如何格式化此数据的更多详细信息,请参阅示例。 |
|
当 如果为 选项
|
|
加载到注册表中的 hive 键的路径,例如 C:\Users\Default\NTUSER.DAT。 此 hive 加载在 HKLM:\ANSIBLE 键下,然后可以像任何其他路径一样在 *name* 中使用。 这可以用于加载默认用户配置文件注册表 hive 或任何其他保存为文件的 hive。 使用此功能需要用户启用 |
|
上面 如果未提供或为空,则将使用该键的“(默认)”属性。 |
|
注册表路径的名称。 应位于以下注册表 hive 之一:HKCC、HKCR、HKCU、HKLM、HKU。 |
|
注册表项的状态。 选项
|
|
注册表值的类型。 选项
|
备注
注意
支持检查模式
-C/--check
和 diff 输出-D/--diff
,以便您可以在应用更改之前针对活动配置测试每个更改。注意,某些注册表 hive(特别是
HKEY_USERS
)不允许在根文件夹中创建新的注册表路径。
另请参阅
另请参阅
- ansible.windows.win_reg_stat
获取有关 Windows 注册表键的信息。
- community.windows.win_regmerge
将注册表文件的内容合并到 Windows 注册表中。
示例
- name: Create registry path MyCompany
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
- name: Add or update registry path MyCompany, with entry 'hello', and containing 'world'
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
name: hello
data: world
- name: Add or update registry path MyCompany, with dword entry 'hello', and containing 1337 as the decimal value
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
name: hello
data: 1337
type: dword
- name: Add or update registry path MyCompany, with dword entry 'hello', and containing 0xff2500ae as the hex value
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
name: hello
data: 0xff2500ae
type: dword
- name: Add or update registry path MyCompany, with binary entry 'hello', and containing binary data in hex-string format
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
name: hello
data: hex:be,ef,be,ef,be,ef,be,ef,be,ef
type: binary
- name: Add or update registry path MyCompany, with binary entry 'hello', and containing binary data in yaml format
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
name: hello
data: [0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef, 0xbe, 0xef]
type: binary
- name: Add or update registry path MyCompany, with expand string entry 'hello'
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
name: hello
data: '%appdata%\local'
type: expandstring
- name: Add or update registry path MyCompany, with multi string entry 'hello'
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
name: hello
data: ['hello', 'world']
type: multistring
- name: Disable keyboard layout hotkey for all users (changes existing)
ansible.windows.win_regedit:
path: HKU:\.DEFAULT\Keyboard Layout\Toggle
name: Layout Hotkey
data: 3
type: dword
- name: Disable language hotkey for current users (adds new)
ansible.windows.win_regedit:
path: HKCU:\Keyboard Layout\Toggle
name: Language Hotkey
data: 3
type: dword
- name: Remove registry path MyCompany (including all entries it contains)
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
state: absent
delete_key: true
- name: Clear the existing (Default) entry at path MyCompany
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
state: absent
delete_key: false
- name: Remove entry 'hello' from registry path MyCompany
ansible.windows.win_regedit:
path: HKCU:\Software\MyCompany
name: hello
state: absent
- name: Change default mouse trailing settings for new users
ansible.windows.win_regedit:
path: HKLM:\ANSIBLE\Control Panel\Mouse
name: MouseTrails
data: 10
type: string
state: present
hive: C:\Users\Default\NTUSER.dat
返回值
常见的返回值在此处有说明 这里,以下是此模块特有的字段
键 |
描述 |
---|---|
此调用是否更改了注册表值中的数据。 返回值:success 示例: |
|
此调用是否更改了注册表值的类型。 返回值:success 示例: |