首页 > 解决方案 > Windows 上的 Ansible:如何更改注册表所有权

问题描述

Ansible 版本:ansible 2.9.2 我试图在配置了 WINRM 的 Windows Server 2012 R2 上的 playbook 下运行。我可以在目录上运行 win_acl 和 win_owner 模块,但是,我在使用 Ansible 更改Registry () 所有权时遇到了问题。注意:我可以通过 RDP 手动将相同的内容更改到本文中提到的服务器 https://github.com/jenkinsci/windows-slaves-plugin/blob/master/docs/troubleshooting.adoc#windows-server- 2012-64位

---
- hosts: all
  gather_facts: no
  tasks:
  - name: Grant Ownership to Administrator user on the registry
    win_acl:
      path: HKLM:\SOFTWARE\Classes\Wow6432Node\CLSID\72C24DD5-D70A-438B-8A42-98424B88AFB8
      user: Administrators
      rights: TakeOwnership
      type: allow
      state: present
      inherit: ContainerInherit
      propagation: 'None'
    Error: {"changed": false, "msg": "an exception occurred when adding the specified rule - Requested registry access is not allowed."}

标签: ansiblewindows-server-2012-r2

解决方案


我无法用纯 ansible 做类似的事情。所以我使用了一个名为 setacl.exe https://helgeklein.com/download/#setacl的外部工具

以下示例是在生产中使用的极端方法。但它会显示您拥有的选项

    - name: Copy setacl.exe to system32
      win_copy:
        src: files/setacl.exe
        dest: C:\windows\system32\setacl.exe
    - name: Change the owner for a part of the registry
      tags: setacl
      raw: setacl.exe -on "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum" -ot reg -rec yes -actn setowner -ownr "n:Administrator"
    - name: Add administrator to reg
      tags: setacl
      raw: setacl.exe -on "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum" -ot reg -rec yes -actn ace -ace "n:Adminiistrator;p:full"

推荐阅读