mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
* Add win_psrepository * Small corrections * Correct requiqurements - add NuGet * Extend tests * Post-review updates * Post-review - updates 2 * Add empty RETURN section in documentation * Add empty line at EOF * Post-review updates 3 * Update tests to run in check_mode too * Minor updates * Correct installing/updating NuGet * a few changes for review * Remove copyrights * Revert "Remove copyrights" This reverts commit 2d687ec6a691d8d71358ae447e0fdc828976a767.
58 lines
2.1 KiB
PowerShell
58 lines
2.1 KiB
PowerShell
#!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
|