community.windows.win_psexec 模块 – 以其他(特权)用户身份运行命令(远程)

注意

此模块是 community.windows 集合(版本 2.3.0)的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.windows。您需要其他要求才能使用此模块,有关详细信息,请参见 要求

要在playbook中使用它,请指定: community.windows.win_psexec

概要

  • 通过PsExec服务(远程)运行命令。

  • 以其他(域)用户身份(具有提升的权限)运行命令。

要求

执行此模块的主机需要以下要求。

  • Microsoft PsExec

参数

参数

注释

chdir

path

从此(远程)目录运行命令。

command

字符串 / 必需

通过PsExec运行的命令行(限制为260个字符)。

elevated

布尔值

以提升的权限运行命令。

选项

  • false ← (默认)

  • true

executable

path

PsExec实用程序的位置(如果它不在您的PATH中)。

默认值: "psexec.exe"

hostnames

列表 / 元素=字符串

运行命令的主机名。

如果未提供,则在本地运行命令。

interactive

布尔值

运行程序,以便它与远程系统上的桌面交互。

选项

  • false ← (默认)

  • true

limited

布尔值

以受限用户身份运行命令(删除管理员组,只允许分配给用户组的权限)。

选项

  • false ← (默认)

  • true

nobanner

布尔值

不显示启动横幅和版权信息。

这仅适用于特定版本的PsExec二进制文件。

选项

  • false ← (默认)

  • true

noprofile

布尔值

在不加载帐户配置文件的情况下运行命令。

选项

  • false ← (默认)

  • true

password

字符串

以其运行命令的(远程)用户的密码。

这是进行身份验证所必需的。

priority

字符串

用于以不同的优先级运行命令。

选项

  • "abovenormal"

  • "background"

  • "belownormal"

  • "high"

  • "low"

  • "realtime"

session

整数

指定要使用的会话ID。

此参数与interactive一起使用。

interactive设置为no时,它不起作用。

system

布尔值

在系统帐户中运行远程命令。

选项

  • false ← (默认)

  • true

timeout

整数

连接超时(秒)

username

字符串

以其运行命令的(远程)用户。

如果未提供,则使用当前用户。

wait

布尔值

等待应用程序终止。

仅用于非交互式应用程序。

选项

  • false

  • true ← (默认)

备注

注意

另请参阅

另请参阅

community.windows.psexec

基于PsExec模型在远程Windows主机上运行命令。

ansible.builtin.raw

执行低级命令。

ansible.windows.win_command

在远程Windows节点上执行命令。

ansible.windows.win_shell

在目标主机上执行shell命令。

示例

- name: Test the PsExec connection to the local system (target node) with your user
  community.windows.win_psexec:
    command: whoami.exe

- name: Run regedit.exe locally (on target node) as SYSTEM and interactively
  community.windows.win_psexec:
    command: regedit.exe
    interactive: true
    system: true

- name: Run the setup.exe installer on multiple servers using the Domain Administrator
  community.windows.win_psexec:
    command: E:\setup.exe /i /IACCEPTEULA
    hostnames:
      - remote_server1
      - remote_server2
    username: DOMAIN\Administrator
    password: some_password
    priority: high

- name: Run PsExec from custom location C:\Program Files\sysinternals\
  community.windows.win_psexec:
    command: netsh advfirewall set allprofiles state off
    executable: C:\Program Files\sysinternals\psexec.exe
    hostnames: [remote_server]
    password: some_password
    priority: low

返回值

常见的返回值已在 此处 记录,以下是此模块特有的字段

描述

cmd

字符串

模块使用的完整命令行,包括PsExec调用和其他选项。

返回:始终

示例: "psexec.exe -nobanner \\\\remote_server -u \"DOMAIN\\Administrator\" -p \"some_password\" -accepteula E:\\setup.exe"

pid

整数

PsExec创建的异步进程的PID。

返回:wait=False

示例: 1532

rc

整数

命令的返回码。

返回:始终

示例: 0

stderr

字符串

命令的错误输出。

返回:始终

示例: "Error 15 running E:\\setup.exe"

stdout

字符串

命令的标准输出。

返回:始终

示例: "Success."

作者

  • Dag Wieers (@dagwieers)