Ansible - 如何以提升的权限执行 powershell win_command

use*_*708 2 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
Run Code Online (Sandbox Code Playgroud)

这工作正常,因为它不需要提升权限,但如果我尝试需要 runas 管理员的东西,我似乎无法弄清楚,尝试添加 'become_method: runas' 不走运?

imj*_*gel 6

它应该这样工作:

- 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
Run Code Online (Sandbox Code Playgroud)