Ansible-如何将powershell win_命令作为提升权限执行

Ansible-如何将powershell win_命令作为提升权限执行,ansible,Ansible,正在寻找如何使用提升权限执行powershell win_命令的指导 我的剧本示例: --- - name: Run powershell script hosts: win gather_facts: false tasks: - name: windows test command win_command: powershell.exe - args: stdin: ipconfig >> c:\ipconfi

正在寻找如何使用提升权限执行powershell win_命令的指导

我的剧本示例:

    ---
- name: Run powershell script
  hosts: win
  gather_facts: false
  tasks:
    - name: windows test command
      win_command: powershell.exe -
      args: 
        stdin: ipconfig >> c:\ipconfig.txt

这很好,因为它不需要提升权限,但是如果我尝试一些需要运行方式管理员的东西,我似乎无法理解,尝试添加“Been_method:runas”no luck?

它应该是这样工作的:

- 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

它应该这样工作:

- 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

需要注意的是,首先作为管理员通过winrm连接是不够的。对于某些操作,如在Windows 2012上安装KB3035131,仍然需要“是”,请注意,首先作为管理员通过winrm连接是不够的。对于某些操作,例如在Windows 2012上安装KB3035131,仍然需要“是”