ansible win_command 失敗但在手動執行命令時有效
我正在嘗試執行 New-WdsClient PowerShell cmdlet 或 wdsutil /add-device,我真的不在乎最終使用哪個,只要它有效。
當我執行 ‘wdsutil.exe /add-device /device:new_client /id:aabbccddeeff /BootImagePath:“Boot\x64\Images\boot-(6).wim” ’ 它工作,當我從 Ansible 執行相同的我得到
"stdout_lines": [ "", "Windows Deployment Services Management Utility [Version 10.0.14393.0]", "© 2016 Microsoft Corporation. All rights reserved.", "", "", "An error occurred while trying to execute the command.", "Error Code: 0xC103013A", "Error Description: The specified server name is invalid or does not exist in the directory service.", ""
我完全被難住了。
Ansible 的作用只是:
- name: Pre Stage WDS Client win_command: powershell.exe - args: stdin: 'wdsutil.exe /add-device /device:{{ var_wds_client_name }} /id:{{ var_wds_client_mac }} /BootImagePath:"Boot\x64\Images\boot-(6).wim"'
使用 New-WdsClient 我什至沒有走到這一步……
有任何想法嗎?
– 編輯 1 –
當我將 win_whoami 作為臨時執行時,它可以工作:
ansible wds-server --become --become-method runas --become-user DOMAIN\Administrator --module-name win_whoami 2> /dev/null| egrep "SeDebug|High" "account_name": "High Mandatory Level", "account_name": "High Mandatory Level", "SeDebugPrivilege": "enabled"
當我以 adhoc 方式執行 wdsutil 時,
ansible wds-server --become --become-method runas --become-user DOMAIN\Administrator --module-name win_command -a "wdsutil.exe /add-device /device:client /id:0001a5a0c267 /BootImagePath:Boot\x64\Images\boot-(6).wim"
我得到:
Windows Deployment Services Management Utility [Version 10.0.14393.0] © 2016 Microsoft Corporation. All rights reserved.
嘗試執行命令時出錯。錯誤程式碼:0xC103013A 錯誤描述:指定的伺服器名稱無效或目錄服務中不存在。
非零返回碼
首先,向大家道歉。
Ansible 服務是一個 RHEL 盒子,它實際上與一個中間 Windows 盒子對話,後者隨後與 WDS 伺服器對話。
我的一位同事發現這個連結為我們解決了這個問題。
謝謝大家的建議。
這是一個猜測,因為我沒有方便的 Windows WDS 部署來執行測試。
wdsutil
根據Microsoft Docs的說法,我認為由於缺乏所需的提升權限,該任務沒有通過 Ansible 執行。您可能需要使用become
關鍵字才能使任務工作:- name: Pre Stage WDS Client win_command: powershell.exe - args: stdin: 'wdsutil.exe /add-device /device:{{ var_wds_client_name }} /id:{{ var_wds_client_mac }} /BootImagePath:"Boot\x64\Images\boot-(6).wim"' become: yes become_method: runas
或者,或者,
wdsutil
直接呼叫:- name: Pre Stage WDS Client win_command: 'wdsutil.exe /add-device /device:{{ var_wds_client_name }} /id:{{ var_wds_client_mac }} /BootImagePath:"Boot\x64\Images\boot-(6).wim"' become: yes become_method: runas
使用以下臨時呼叫檢查是否授予 Ansible 管理權限:
$ ansible windows_wds_server --become --become-method runas --module-name win_whoami
返回的 JSON 對象應將
privileges.SeDebugPrivilege
屬性設置為enabled
.參考:https ://docs.ansible.com/ansible/latest/user_guide/become.html#administrative-rights