Ansible-如何将Powershell Win_command作为提升的特权执行

时间:2018-06-27 12:11:59

标签: ansible

正在寻找有关如何以提升的特权执行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?

1 个答案:

答案 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