summaryrefslogtreecommitdiff
path: root/lib/ansible/modules/windows/win_psrepository.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/modules/windows/win_psrepository.ps1')
-rw-r--r--lib/ansible/modules/windows/win_psrepository.ps158
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/ansible/modules/windows/win_psrepository.ps1 b/lib/ansible/modules/windows/win_psrepository.ps1
new file mode 100644
index 0000000000..7aec08fb24
--- /dev/null
+++ b/lib/ansible/modules/windows/win_psrepository.ps1
@@ -0,0 +1,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