blob: 7aec08fb24d5fbbbbac66f2ab83130813287cbbd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!powershell
# Copyright: (c) 2017, Daniele Lazzari <lazzari@mailup.com>
# Copyright: (c) 2018, Wojciech Sciesinski <wojciech[at]sciesinski[dot]net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#Requires -Module Ansible.ModuleUtils.Legacy
# win_psrepository (Windows PowerShell repositories Additions/Removals/Updates)
$params = Parse-Args -arguments $args -supports_check_mode $true
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
$name = Get-AnsibleParam -obj $params -name "name" -type "str" -failifempty $true
$source = Get-AnsibleParam -obj $params -name "source" -type "str"
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "present", "absent"
$installationpolicy = Get-AnsibleParam -obj $params -name "installation_policy" -type "str" -validateset "trusted", "untrusted"
$result = @{"changed" = $false}
$Repo = Get-PSRepository -Name $name -ErrorAction Ignore
if ($state -eq "present") {
if ($null -eq $Repo){
if ($null -eq $installationpolicy) {
$installationpolicy = "trusted"
}
if (-not $check_mode) {
Register-PSRepository -Name $name -SourceLocation $source -InstallationPolicy $installationpolicy
}
$result.changed = $true
}
else {
$changed_properties = @{}
if ($Repo.SourceLocation -ne $source) {
$changed_properties.SourceLocation = $source
}
if ($null -ne $installationpolicy -and $Repo.InstallationPolicy -ne $installationpolicy) {
$changed_properties.InstallationPolicy = $installationpolicy
}
if ($changed_properties.Count -gt 0) {
if (-not $check_mode) {
Set-PSRepository -Name $name @changed_properties
}
$result.changed = $true
}
}
}
elseif ($state -eq "absent" -and $null -ne $Repo) {
if (-not $check_mode) {
Unregister-PSRepository -Name $name
}
$result.changed = $true
}
Exit-Json -obj $result
|