community.windows.win_psmodule 模块 – 添加或删除 Windows PowerShell 模块

注意

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

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

要安装它,请使用:ansible-galaxy collection install community.windows

要在剧本中使用它,请指定:community.windows.win_psmodule

概要

  • 此模块有助于在基于 Windows 的系统上安装 Windows PowerShell 模块并在 Windows 系统上注册自定义模块存储库。

参数

参数

注释

accept_license

布尔值

在 community.windows 1.11.0 中添加

接受模块的许可证。

对于需要接受许可证的模块是必需的,因为无法交互式地回答提示。

对应于 -AcceptLicense 参数的 Install-Module

在检查模式下无法检测到需要接受许可证的模块或依赖项的安装,但除非 *accept_license=true*,否则会在运行时导致失败。

选项

  • false ← (默认)

  • true

allow_clobber

布尔值

如果 yes 允许安装包含与已存在命令同名的命令的模块。

选项

  • false ← (默认)

  • true

allow_prerelease

布尔值

如果 yes 安装标记为预发布的模块。

它不适用于参数 minimum_version 和/或 maximum_version

它不适用于设置为 absent 的 state

选项

  • false ← (默认)

  • true

force

布尔值

在 community.windows 1.13.0 中添加

覆盖有关模块安装冲突的警告消息

如果存在具有相同名称和版本的模块,则 force 会覆盖该版本

对应于 -Force 参数的 Install-Module

如果模块作为依赖项,它还会强制重新安装依赖项。如果模块清单中未指定版本,则将其更新到最新版本。

选项

  • false ← (默认)

  • true

maximum_version

字符串

必须安装的 PowerShell 模块的最大版本。

minimum_version

字符串

必须安装的 PowerShell 模块的最小版本。

name

字符串 / 必需

必须安装的 Windows PowerShell 模块的名称。

password

字符串

在 community.windows 1.10.0 中添加

用于对私有存储库进行身份验证的密码。

repository

字符串

要使用的自定义存储库的名称。

required_version

字符串

必须安装的 PowerShell 模块的精确版本。

skip_publisher_check

布尔值

如果 yes,允许您安装与计算机上已存在的模块不同的版本,在这种情况下,不同的模块未由受信任的发布者进行数字签名,而最新的现有模块已由受信任的发布者进行数字签名。

选项

  • false ← (默认)

  • true

state

字符串

如果 present 安装新模块。

如果 absent 删除模块。

如果 latest 将模块更新到最新版本。

选项

  • "absent"

  • "latest"

  • "present" ← (默认)

username

字符串

在 community.windows 1.10.0 中添加

用于对私有存储库进行身份验证的用户名。

备注

注意

  • 需要的 PowerShell 模块 - PowerShellGet >= 1.6.0 - PackageManagement >= 1.1.7

  • 需要的 PowerShell 包提供程序 - NuGet >= 2.8.5.201

  • 在 PowerShell 5.x 上,在 win_psmodule 模块的第一次运行中,将更新所需的模块和包提供程序。

  • 在 PowerShell 3.x 和 4.x 上,您必须在使用 win_psmodule 之前安装它们。

另请参阅

另请参阅

community.windows.win_psrepository

添加、删除或更新 Windows PowerShell 存储库。

示例

---
- name: Add a PowerShell module
  community.windows.win_psmodule:
    name: PowerShellModule
    state: present

- name: Add an exact version of PowerShell module
  community.windows.win_psmodule:
    name: PowerShellModule
    required_version: "4.0.2"
    state: present

- name: Install or update an existing PowerShell module to the newest version
  community.windows.win_psmodule:
    name: PowerShellModule
    state: latest

- name: Install newer version of built-in Windows module
  community.windows.win_psmodule:
    name: Pester
    skip_publisher_check: true
    state: present

- name: Add a PowerShell module and register a repository
  community.windows.win_psmodule:
    name: MyCustomModule
    repository: MyRepository
    state: present

- name: Add a PowerShell module from a specific repository
  community.windows.win_psmodule:
    name: PowerShellModule
    repository: MyRepository
    state: present

- name: Add a PowerShell module from a specific repository with credentials
  win_psmodule:
    name: PowerShellModule
    repository: MyRepository
    username: repo_username
    password: repo_password
    state: present

- name: Remove a PowerShell module
  community.windows.win_psmodule:
    name: PowerShellModule
    state: absent

返回值

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

描述

nuget_changed

布尔值

安装 NuGet 包提供程序时为 True。

返回:始终

示例:true

output

字符串

描述任务结果的消息。

返回:始终

示例:"Module PowerShellCookbook installed"

repository_changed

布尔值

安装或移除自定义资源库时为真。

返回:始终

示例:true

作者

  • Wojciech Sciesinski (@it-praktyk)

  • Daniele Lazzari (@dlazz)