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

概要

参数

参数

注释

data

任意

pathname 注册表项的值。

如果未指定,则该属性的值对于相应的 type 将为 null。

二进制和 None 数据应以 yaml 字节数组或逗号分隔的十六进制值表示。

一种简单的方法是运行 regedit.exe 并使用“导出”选项将注册表值保存到文件。

在导出的文件中,二进制值将类似于 hex:be,ef,be,efhex: 前缀是可选的。

DWORD 和 QWORD 值应表示为十进制数或十六进制值。

多字符串值应作为列表传递。

有关如何格式化此数据的更多详细信息,请参阅示例。

delete_key

布尔值

state 为“absent”时,这将删除整个键。

如果为 false,则它只会清除该键的“(默认)”属性。

选项

  • false

  • true ← (默认)

hive

path

加载到注册表中的 hive 键的路径,例如 C:\Users\Default\NTUSER.DAT。

此 hive 加载在 HKLM:\ANSIBLE 键下,然后可以像任何其他路径一样在 *name* 中使用。

这可以用于加载默认用户配置文件注册表 hive 或任何其他保存为文件的 hive。

使用此功能需要用户启用 SeRestorePrivilegeSeBackupPrivilege 权限。

name

别名:entry、value

字符串

上面 path 参数中注册表项的名称。

如果未提供或为空,则将使用该键的“(默认)”属性。

path

别名:key

字符串 / 必需

注册表路径的名称。

应位于以下注册表 hive 之一:HKCC、HKCR、HKCU、HKLM、HKU。

state

字符串

注册表项的状态。

选项

  • "absent"

  • "present" ← (默认)

type

别名:datatype

字符串

注册表值的类型。

选项

  • "none"

  • "binary"

  • "dword"

  • "expandstring"

  • "multistring"

  • "string" ← (默认)

  • "qword"

备注

注意

  • 支持检查模式 -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

返回值

常见的返回值在此处有说明 这里,以下是此模块特有的字段

描述

data_changed

布尔值

此调用是否更改了注册表值中的数据。

返回值:success

示例:false

data_type_changed

布尔值

此调用是否更改了注册表值的类型。

返回值:success

示例: true

作者

  • Adam Keech (@smadam813)

  • Josh Ludwig (@joshludwig)

  • Jordan Borean (@jborean93)