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 存储库。
要求
执行此模块的主机上需要以下要求。
PowerShell 模块 PowerShellGet >= 1.6.0
PowerShell 模块 PackageManagement >= 1.1.7
PowerShell 包提供程序
NuGet
>= 2.8.5.201
参数
参数 |
注释 |
---|---|
如果 当 state=absent 时,force 没有效果。有关其他上下文,请参阅备注。 选项
|
|
设置存储库的 创建新存储库或与 force=True 一起使用时,默认为 选项
|
|
要使用的存储库的名称。 |
|
用于针对私有存储库进行身份验证的密码。 |
|
用于存储库的代理。 |
|
指定用于将模块发布到此存储库的 URI。 |
|
指定用于将脚本发布到此存储库的 URI。 |
|
指定用于从此存储库发现和安装脚本的 URI。 |
|
指定用于从此存储库发现和安装模块的 URI。 URI 可以是 NuGet 服务器馈送(最常见的情况)、HTTP、HTTPS、FTP 或文件位置。 在注册新存储库或使用 force=True 时必需。 |
|
如果 如果 选项
|
|
用于针对私有存储库进行身份验证的用户名。 |
备注
注意
请参阅有关如何更新 NuGet 包提供程序的示例。
您不能使用
win_psrepository
重新注册(添加)已删除的 PSGallery,请改用命令Register-PSRepository -Default
。当注册或设置 source_location 时,PowerShellGet 将根据内部规则转换位置,例如遵循 HTTP/S 重定向。
这可能会导致每次运行都显示
CHANGED
状态,因为这些值永远不会匹配,并且每次都会被“重置”。为了解决这个问题,请使用 community.windows.win_psrepository_info 或
Get-PSRepository
查找真实的目标值,并更新剧本以匹配。更新现有存储库时,除 name 之外的所有选项都是可选的。只会更新提供的选项。使用 force=True 可以精确匹配。
script_location、publish_location 和 script_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