正在寻找有关如何以提升的特权执行powershell win_command的指导。
我的剧本示例:
---
- name: Run powershell script
hosts: win
gather_facts: false
tasks:
- name: windows test command
win_command: powershell.exe -
args:
stdin: ipconfig >> c:\ipconfig.txt
这很好,因为它不需要提升的特权,但是如果我尝试一些需要运行身份管理员的人,我似乎无法弄清楚,请尝试添加'become_method:runas'no lucky?
答案 0 :(得分:2)
它应该这样工作:
- name: Run powershell script
hosts: win
gather_facts: false
become_method: runas
vars:
ansible_become_password: "{{ password }}"
tasks:
- win_command: powershell.exe -
args:
stdin: ipconfig >> c:\ipconfig.txt
become: yes
become_user: Administrator