| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2018, Wojciech Sciesinski <wojciech[at]sciesinski[dot]net> |
| 5 |
# Copyright: (c) 2017, Daniele Lazzari <[email protected]> |
| 6 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
DOCUMENTATION = r''' |
| 9 |
--- |
| 10 |
module: win_psmodule |
| 11 |
short_description: Adds or removes a Windows PowerShell module |
| 12 |
description: |
| 13 |
- This module helps to install Windows PowerShell modules and register custom modules repository on Windows-based systems. |
| 14 |
options: |
| 15 |
name: |
| 16 |
description: |
| 17 |
- Name of the Windows PowerShell module that has to be installed. |
| 18 |
type: str |
| 19 |
required: yes |
| 20 |
state: |
| 21 |
description: |
| 22 |
- If C(present) a new module is installed. |
| 23 |
- If C(absent) a module is removed. |
| 24 |
- If C(latest) a module is updated to the newest version. |
| 25 |
type: str |
| 26 |
choices: [ absent, latest, present ] |
| 27 |
default: present |
| 28 |
required_version: |
| 29 |
description: |
| 30 |
- The exact version of the PowerShell module that has to be installed. |
| 31 |
type: str |
| 32 |
minimum_version: |
| 33 |
description: |
| 34 |
- The minimum version of the PowerShell module that has to be installed. |
| 35 |
type: str |
| 36 |
maximum_version: |
| 37 |
description: |
| 38 |
- The maximum version of the PowerShell module that has to be installed. |
| 39 |
type: str |
| 40 |
allow_clobber: |
| 41 |
description: |
| 42 |
- If C(yes) allows install modules that contains commands those have the same names as commands that already exists. |
| 43 |
type: bool |
| 44 |
default: no |
| 45 |
skip_publisher_check: |
| 46 |
description: |
| 47 |
- If C(yes), allows you to install a different version of a module that already exists on your computer in the case when a different one |
| 48 |
is not digitally signed by a trusted publisher and the newest existing module is digitally signed by a trusted publisher. |
| 49 |
type: bool |
| 50 |
default: no |
| 51 |
allow_prerelease: |
| 52 |
description: |
| 53 |
- If C(yes) installs modules marked as prereleases. |
| 54 |
- It doesn't work with the parameters C(minimum_version) and/or C(maximum_version). |
| 55 |
- It doesn't work with the C(state) set to absent. |
| 56 |
type: bool |
| 57 |
default: no |
| 58 |
repository: |
| 59 |
description: |
| 60 |
- Name of the custom repository to use. |
| 61 |
type: str |
| 62 |
username: |
| 63 |
description: |
| 64 |
- Username to authenticate against private repository. |
| 65 |
type: str |
| 66 |
required: no |
| 67 |
version_added: '1.10.0' |
| 68 |
password: |
| 69 |
description: |
| 70 |
- Password to authenticate against private repository. |
| 71 |
type: str |
| 72 |
required: no |
| 73 |
version_added: '1.10.0' |
| 74 |
accept_license: |
| 75 |
description: |
| 76 |
- Accepts the module's license. |
| 77 |
- Required for modules that require license acceptance, since interactively answering the prompt is not possible. |
| 78 |
- Corresponds to the C(-AcceptLicense) parameter of C(Install-Module). |
| 79 |
- >- |
| 80 |
Installation of a module or a dependency that requires license acceptance cannot be detected in check mode, |
| 81 |
but will cause a failure at runtime unless I(accept_license=true). |
| 82 |
type: bool |
| 83 |
required: no |
| 84 |
default: false |
| 85 |
version_added: '1.11.0' |
| 86 |
force: |
| 87 |
description: |
| 88 |
- Overrides warning messages about module installation conflicts |
| 89 |
- If there is an existing module with the same name and version, force overwrites that version |
| 90 |
- Corresponds to the C(-Force) parameter of C(Install-Module). |
| 91 |
- >- |
| 92 |
If module as dependency, it will also force reinstallation of dependency. |
| 93 |
Updating them to latest if version isn't specified in module manifest. |
| 94 |
type: bool |
| 95 |
required: no |
| 96 |
default: false |
| 97 |
version_added: '1.13.0' |
| 98 |
notes: |
| 99 |
- PowerShell modules needed |
| 100 |
- PowerShellGet >= 1.6.0 |
| 101 |
- PackageManagement >= 1.1.7 |
| 102 |
- PowerShell package provider needed |
| 103 |
- NuGet >= 2.8.5.201 |
| 104 |
- On PowerShell 5.x required modules and a package provider will be updated under the first run of the win_psmodule module. |
| 105 |
- On PowerShell 3.x and 4.x you have to install them before using the win_psmodule. |
| 106 |
seealso: |
| 107 |
- module: community.windows.win_psrepository |
| 108 |
author: |
| 109 |
- Wojciech Sciesinski (@it-praktyk) |
| 110 |
- Daniele Lazzari (@dlazz) |
| 111 |
''' |
| 112 |
|
| 113 |
EXAMPLES = r''' |
| 114 |
--- |
| 115 |
- name: Add a PowerShell module |
| 116 |
community.windows.win_psmodule: |
| 117 |
name: PowerShellModule |
| 118 |
state: present |
| 119 |
|
| 120 |
- name: Add an exact version of PowerShell module |
| 121 |
community.windows.win_psmodule: |
| 122 |
name: PowerShellModule |
| 123 |
required_version: "4.0.2" |
| 124 |
state: present |
| 125 |
|
| 126 |
- name: Install or update an existing PowerShell module to the newest version |
| 127 |
community.windows.win_psmodule: |
| 128 |
name: PowerShellModule |
| 129 |
state: latest |
| 130 |
|
| 131 |
- name: Install newer version of built-in Windows module |
| 132 |
community.windows.win_psmodule: |
| 133 |
name: Pester |
| 134 |
skip_publisher_check: true |
| 135 |
state: present |
| 136 |
|
| 137 |
- name: Add a PowerShell module and register a repository |
| 138 |
community.windows.win_psmodule: |
| 139 |
name: MyCustomModule |
| 140 |
repository: MyRepository |
| 141 |
state: present |
| 142 |
|
| 143 |
- name: Add a PowerShell module from a specific repository |
| 144 |
community.windows.win_psmodule: |
| 145 |
name: PowerShellModule |
| 146 |
repository: MyRepository |
| 147 |
state: present |
| 148 |
|
| 149 |
- name: Add a PowerShell module from a specific repository with credentials |
| 150 |
win_psmodule: |
| 151 |
name: PowerShellModule |
| 152 |
repository: MyRepository |
| 153 |
username: repo_username |
| 154 |
password: repo_password |
| 155 |
state: present |
| 156 |
|
| 157 |
- name: Remove a PowerShell module |
| 158 |
community.windows.win_psmodule: |
| 159 |
name: PowerShellModule |
| 160 |
state: absent |
| 161 |
''' |
| 162 |
|
| 163 |
RETURN = r''' |
| 164 |
--- |
| 165 |
output: |
| 166 |
description: A message describing the task result. |
| 167 |
returned: always |
| 168 |
sample: "Module PowerShellCookbook installed" |
| 169 |
type: str |
| 170 |
nuget_changed: |
| 171 |
description: True when Nuget package provider is installed. |
| 172 |
returned: always |
| 173 |
type: bool |
| 174 |
sample: true |
| 175 |
repository_changed: |
| 176 |
description: True when a custom repository is installed or removed. |
| 177 |
returned: always |
| 178 |
type: bool |
| 179 |
sample: true |
| 180 |
''' |