| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2020, Brian Scholer <@briantist> |
| 5 |
# Copyright: (c) 2018, Wojciech Sciesinski <wojciech[at]sciesinski[dot]net> |
| 6 |
# Copyright: (c) 2017, Daniele Lazzari <[email protected]> |
| 7 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 8 |
|
| 9 |
DOCUMENTATION = r''' |
| 10 |
--- |
| 11 |
module: win_psrepository |
| 12 |
short_description: Adds, removes or updates a Windows PowerShell repository. |
| 13 |
description: |
| 14 |
- This module helps to add, remove and update Windows PowerShell repository on Windows-based systems. |
| 15 |
options: |
| 16 |
name: |
| 17 |
description: |
| 18 |
- Name of the repository to work with. |
| 19 |
type: str |
| 20 |
required: yes |
| 21 |
source_location: |
| 22 |
description: |
| 23 |
- Specifies the URI for discovering and installing modules from this repository. |
| 24 |
- A URI can be a NuGet server feed (most common situation), HTTP, HTTPS, FTP or file location. |
| 25 |
- Required when registering a new repository or using I(force=True). |
| 26 |
type: str |
| 27 |
aliases: |
| 28 |
- source |
| 29 |
script_source_location: |
| 30 |
description: |
| 31 |
- Specifies the URI for discovering and installing scripts from this repository. |
| 32 |
type: str |
| 33 |
publish_location: |
| 34 |
description: |
| 35 |
- Specifies the URI for publishing modules to this repository. |
| 36 |
type: str |
| 37 |
script_publish_location: |
| 38 |
description: |
| 39 |
- Specifies the URI for publishing scripts to this repository. |
| 40 |
type: str |
| 41 |
state: |
| 42 |
description: |
| 43 |
- If C(present) a new repository is added or updated. |
| 44 |
- If C(absent) a repository is removed. |
| 45 |
type: str |
| 46 |
choices: [ absent, present ] |
| 47 |
default: present |
| 48 |
installation_policy: |
| 49 |
description: |
| 50 |
- Sets the C(InstallationPolicy) of a repository. |
| 51 |
- Will default to C(trusted) when creating a new repository or used with I(force=True). |
| 52 |
type: str |
| 53 |
choices: [ trusted, untrusted ] |
| 54 |
force: |
| 55 |
description: |
| 56 |
- If C(True), any differences from the desired state will result in the repository being unregistered, and then re-registered. |
| 57 |
- I(force) has no effect when I(state=absent). See notes for additional context. |
| 58 |
type: bool |
| 59 |
default: False |
| 60 |
proxy: |
| 61 |
description: |
| 62 |
- Proxy to use for repository. |
| 63 |
type: str |
| 64 |
required: no |
| 65 |
version_added: 1.1.0 |
| 66 |
username: |
| 67 |
description: |
| 68 |
- Username to authenticate against private repository. |
| 69 |
type: str |
| 70 |
required: no |
| 71 |
version_added: '1.10.0' |
| 72 |
password: |
| 73 |
description: |
| 74 |
- Password to authenticate against private repository. |
| 75 |
type: str |
| 76 |
required: no |
| 77 |
version_added: '1.10.0' |
| 78 |
requirements: |
| 79 |
- PowerShell Module L(PowerShellGet >= 1.6.0,https://www.powershellgallery.com/packages/PowerShellGet/) |
| 80 |
- PowerShell Module L(PackageManagement >= 1.1.7,https://www.powershellgallery.com/packages/PackageManagement/) |
| 81 |
- PowerShell Package Provider C(NuGet) >= 2.8.5.201 |
| 82 |
notes: |
| 83 |
- See the examples on how to update the NuGet package provider. |
| 84 |
- You can not use C(win_psrepository) to re-register (add) removed PSGallery, use the command C(Register-PSRepository -Default) instead. |
| 85 |
- When registering or setting I(source_location), PowerShellGet will transform the location according to internal rules, such as following HTTP/S redirects. |
| 86 |
- This can result in a C(CHANGED) status on each run as the values will never match and will be "reset" each time. |
| 87 |
- To work around that, find the true destination value with M(community.windows.win_psrepository_info) or C(Get-PSRepository) and update the playbook to |
| 88 |
match. |
| 89 |
- When updating an existing repository, all options except I(name) are optional. Only supplied options will be updated. Use I(force=True) to exactly match. |
| 90 |
- I(script_location), I(publish_location), and I(script_publish_location) are optional but once set can only be cleared with I(force=True). |
| 91 |
- Using I(force=True) will unregister and re-register the repository if there are any changes, so that it exactly matches the options specified. |
| 92 |
seealso: |
| 93 |
- module: community.windows.win_psrepository_info |
| 94 |
- module: community.windows.win_psmodule |
| 95 |
author: |
| 96 |
- Wojciech Sciesinski (@it-praktyk) |
| 97 |
- Brian Scholer (@briantist) |
| 98 |
''' |
| 99 |
|
| 100 |
EXAMPLES = r''' |
| 101 |
--- |
| 102 |
- name: Ensure the required NuGet package provider version is installed |
| 103 |
ansible.windows.win_shell: Find-PackageProvider -Name Nuget -ForceBootstrap -IncludeDependencies -Force |
| 104 |
|
| 105 |
- name: Register a PowerShell repository |
| 106 |
community.windows.win_psrepository: |
| 107 |
name: MyRepository |
| 108 |
source_location: https://myrepo.com |
| 109 |
state: present |
| 110 |
|
| 111 |
- name: Remove a PowerShell repository |
| 112 |
community.windows.win_psrepository: |
| 113 |
name: MyRepository |
| 114 |
state: absent |
| 115 |
|
| 116 |
- name: Add an untrusted repository |
| 117 |
community.windows.win_psrepository: |
| 118 |
name: MyRepository |
| 119 |
installation_policy: untrusted |
| 120 |
|
| 121 |
- name: Add a repository with different locations |
| 122 |
community.windows.win_psrepository: |
| 123 |
name: NewRepo |
| 124 |
source_location: https://myrepo.example/module/feed |
| 125 |
script_source_location: https://myrepo.example/script/feed |
| 126 |
publish_location: https://myrepo.example/api/module/publish |
| 127 |
script_publish_location: https://myrepo.example/api/script/publish |
| 128 |
|
| 129 |
- name: Update only two properties on the above repository |
| 130 |
community.windows.win_psrepository: |
| 131 |
name: NewRepo |
| 132 |
installation_policy: untrusted |
| 133 |
script_publish_location: https://scriptprocessor.example/publish |
| 134 |
|
| 135 |
- name: Clear script locations from the above repository by re-registering it |
| 136 |
community.windows.win_psrepository: |
| 137 |
name: NewRepo |
| 138 |
installation_policy: untrusted |
| 139 |
source_location: https://myrepo.example/module/feed |
| 140 |
publish_location: https://myrepo.example/api/module/publish |
| 141 |
force: true |
| 142 |
|
| 143 |
- name: Register a PowerShell repository with credentials |
| 144 |
community.windows.win_psrepository: |
| 145 |
name: MyRepository |
| 146 |
source_location: https://myrepo.com |
| 147 |
state: present |
| 148 |
username: repo_username |
| 149 |
password: repo_password |
| 150 |
''' |
| 151 |
|
| 152 |
RETURN = ''' |
| 153 |
''' |