community.windows.win_psrepository 模块 – 添加、删除或更新 Windows PowerShell 存储库。

注意

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

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

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

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

概要

  • 此模块有助于在基于 Windows 的系统上添加、删除和更新 Windows PowerShell 存储库。

要求

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

参数

参数

注释

force

布尔值

如果 True,则与所需状态的任何差异都将导致存储库被取消注册,然后重新注册。

state=absent 时,force 没有效果。有关其他上下文,请参阅备注。

选项

  • false ← (默认)

  • true

installation_policy

字符串

设置存储库的 InstallationPolicy

创建新存储库或与 force=True 一起使用时,默认为 trusted

选项

  • "trusted"

  • "untrusted"

name

字符串 / 必需

要使用的存储库的名称。

password

字符串

在 community.windows 1.10.0 中添加

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

proxy

字符串

在 community.windows 1.1.0 中添加

用于存储库的代理。

publish_location

字符串

指定用于将模块发布到此存储库的 URI。

script_publish_location

字符串

指定用于将脚本发布到此存储库的 URI。

script_source_location

字符串

指定用于从此存储库发现和安装脚本的 URI。

source_location

别名:source

字符串

指定用于从此存储库发现和安装模块的 URI。

URI 可以是 NuGet 服务器馈送(最常见的情况)、HTTP、HTTPS、FTP 或文件位置。

在注册新存储库或使用 force=True 时必需。

state

字符串

如果 present,则会添加或更新新存储库。

如果 absent,则会删除存储库。

选项

  • "absent"

  • "present" ← (默认)

username

字符串

在 community.windows 1.10.0 中添加

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

备注

注意

  • 请参阅有关如何更新 NuGet 包提供程序的示例。

  • 您不能使用 win_psrepository 重新注册(添加)已删除的 PSGallery,请改用命令 Register-PSRepository -Default

  • 当注册或设置 source_location 时,PowerShellGet 将根据内部规则转换位置,例如遵循 HTTP/S 重定向。

  • 这可能会导致每次运行都显示 CHANGED 状态,因为这些值永远不会匹配,并且每次都会被“重置”。

  • 为了解决这个问题,请使用 community.windows.win_psrepository_infoGet-PSRepository 查找真实的目标值,并更新剧本以匹配。

  • 更新现有存储库时,除 name 之外的所有选项都是可选的。只会更新提供的选项。使用 force=True 可以精确匹配。

  • script_locationpublish_locationscript_publish_location 是可选的,但一旦设置,只能使用 force=True 清除。

  • 如果存在任何更改,使用 force=True 将取消注册并重新注册存储库,以便它与指定的选项完全匹配。

另请参阅

另请参阅

community.windows.win_psrepository_info

收集有关 PSRepositories 的信息。

community.windows.win_psmodule

添加或删除 Windows PowerShell 模块。

示例

---
- name: Ensure the required NuGet package provider version is installed
  ansible.windows.win_shell: Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force

- name: Register a PowerShell repository
  community.windows.win_psrepository:
    name: MyRepository
    source_location: https://myrepo.com
    state: present

- name: Remove a PowerShell repository
  community.windows.win_psrepository:
    name: MyRepository
    state: absent

- name: Add an untrusted repository
  community.windows.win_psrepository:
    name: MyRepository
    installation_policy: untrusted

- name: Add a repository with different locations
  community.windows.win_psrepository:
    name: NewRepo
    source_location: https://myrepo.example/module/feed
    script_source_location: https://myrepo.example/script/feed
    publish_location: https://myrepo.example/api/module/publish
    script_publish_location: https://myrepo.example/api/script/publish

- name: Update only two properties on the above repository
  community.windows.win_psrepository:
    name: NewRepo
    installation_policy: untrusted
    script_publish_location: https://scriptprocessor.example/publish

- name: Clear script locations from the above repository by re-registering it
  community.windows.win_psrepository:
    name: NewRepo
    installation_policy: untrusted
    source_location: https://myrepo.example/module/feed
    publish_location: https://myrepo.example/api/module/publish
    force: true

- name: Register a PowerShell repository with credentials
  community.windows.win_psrepository:
    name: MyRepository
    source_location: https://myrepo.com
    state: present
    username: repo_username
    password: repo_password

作者

  • Wojciech Sciesinski (@it-praktyk)

  • Brian Scholer (@briantist)