【发布时间】:2016-02-09 09:58:20
【问题描述】:
我正在尝试运行一个简单的剧本来运行 Powershell 脚本。但它一直在失败。如果我直接在服务器上运行 Powershell 脚本,它就可以正常工作。下面是剧本和脚本。 是否需要做一些事情才能让 Ansible 运行 Powershell 脚本?
Powershell 脚本 (rdp.ps1):
set-ItemProperty -Path 'HKLM:SystemCurrentControlSetControlTerminal Server'-name "fDenyTSConnections" -Value 0
剧本:
---
- name: Enable Remote Desktop on
hosts: all
tasks:
- name: Enable Remote Desktop
script: files/Enable_RDP.ps1
错误:
更改:[10.10.3.170] => {“更改”:true,“调用”:{“module_args”:{“_raw_params”:“files/Enable_RDP.ps1”},“module_name”:“脚本”} , "rc": 0, "stderr": "# set-itemproperty:找不到path _x000d__x000a_'hklm:\ systemCurrentControlsetControlTerminal服务器' ps1:2 char:1_x000D__x000A_+ set-ItemProperty -Path 'HKLM:SystemCurrentControlSetControlTerminal _x000D__x000A_Server'-name ..._x000D__x000A_+ ~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~_x000D__x000A_~~~_x000D__x000A_ + CategoryInfo : ObjectNotFound: (HKLM:\SystemCur...Terminal Serv _x000D__x000A_ er:String) [Set-ItemProperty], ItemNotFoundException_x000D__x000A_ + FullyQualifiedErrorId : PathNotFound,Microsoft.Powe rShell.Commands.SetIt _x000D__x000A_ emPropertyCommand_x000D__x000A_ _x000D__x000A_", "stdout": "", "stdout_lines": []}
所以我编辑了剧本以尝试使用“原始”命令运行命令......但这些也失败了。
---
- name: Enable Remote Desktop on
hosts: all
tasks:
- name: Enable Remote Desktop
raw: 'set-ItemProperty -Path "HKLM:SystemCurrentControlSetControlTerminal Server"-name "fDenyTSConnections" -Value 0'
我也试过不带'',像这样:
---
- name: Enable Remote Desktop on
hosts: all
tasks:
- name: Enable Remote Desktop
raw: set-ItemProperty -Path 'HKLM:SystemCurrentControlSetControlTerminal Server'-name "fDenyTSConnections" -Value 0
然后我使用 Raw 命令运行以下 playbook 来创建文件夹。它奏效了。一个非常基本的 Powershell 命令。
---
- name: Enable Remote Desktop on
hosts: all
tasks:
- name: Enable Remote Desktop
raw: New-Item -Path c:\test3 -ItemType directory
什么可能导致一个剧本失败而另一个剧本成功?当然 Ansible 应该能够运行任何 Powershell 脚本?或者是否有某种先决条件或特定方式来编写这些 Powershell 脚本以使其正常工作?
- Ansible 是否能够运行和执行 Powershell 脚本?
- 任何类型的 Powershell 脚本?
- Powershell 脚本是否需要以特定方式编写脚本才能让 Ansible 执行它?
【问题讨论】:
-
我认为您要查找的 HKLM 路径是
HKLM:\System\CurrentControlSet\Control\Terminal Server(注意斜线) -
这正是问题所在!谢谢
标签: powershell ansible ansible-playbook