Skip to content

Commit

Permalink
fix provider to work on puppet 3.6.x and newer
Browse files Browse the repository at this point in the history
  • Loading branch information
rismoney committed Feb 18, 2015
1 parent fab1fad commit 456d11e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
13 changes: 9 additions & 4 deletions lib/puppet/provider/wsuscomputer/wsuscomputer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@
'powershell.exe'
end

@@connstr= "import-module poshwsus | out-null; $null=(Connect-PoshWSUSServer localhost -port 8530)"
def connectstring
"import-module poshwsus | out-null; $null=(Connect-PoshWSUSServer localhost -port 8530)"
end

def exists?
rc=false
args = "#{@@connstr};(GET-PoshWSUSClient -Computer \"#{@resource[:name]}\").computergroup"
connstr = connectstring
args = "#{connstr};(GET-PoshWSUSClient -Computer \"#{@resource[:name]}\").computergroup"
groups=poshexec(args)
rc=true if groups.include?(@resource[:wsusgroup])
return rc
end

def create
args = "#{@@connstr};Add-PoshWSUSClientToGroup -group \"#{@resource[:wsusgroup]}\" -computer \"#{@resource[:name]}\""
connstr = connectstring
args = "#{connstr};Add-PoshWSUSClientToGroup -group \"#{@resource[:wsusgroup]}\" -computer \"#{@resource[:name]}\""
poshexec(args)
end

def destroy
args = "#{@@connstr};Remove-PoshWSUSClientFromGroup -group \"#{@resource[:wsusgroup]}\" -computer \"#{@resource[:name]}\""
connstr = connectstring
args = "#{connstr};Remove-PoshWSUSClientFromGroup -group \"#{@resource[:wsusgroup]}\" -computer \"#{@resource[:name]}\""
poshexec(args)
end

Expand Down
16 changes: 10 additions & 6 deletions lib/puppet/provider/wsusgroup/wsusgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,28 @@
'powershell.exe'
end

@@connstr= "import-module poshwsus | out-null; $null=(Connect-PoshWSUSServer localhost -port 8530)"
def connectstring
"import-module poshwsus | out-null; $null=(Connect-PoshWSUSServer localhost -port 8530)"
end

def exists?
rc=false
args = "#{@@connstr};(GET-PoshWSUSGroup -Name \"#{@resource[:name]}\").Name"
group=poshexec(args)
(group.each {|group| group && rc=true})
connstr = connectstring
args = "#{connstr};(GET-PoshWSUSGroup -Name \"#{@resource[:name]}\").Name"
group=poshexec(args).chomp
rc=true if group==@resource[:name]
return rc
end

def create
args = "#{@@connstr};New-PoshWSUSGroup -Name \"#{@resource[:name]}\""
connstr = connectstring
args = "#{connstr};New-PoshWSUSGroup -Name \"#{@resource[:name]}\""
poshexec(args)
end

def destroy
connstr = connectstring
args = "#{@@connstr};GET-PoshWSUSGroup -Name \"#{@resource[:name]}\" |Remove-PoshWSUSGroup"
poshexec(args)
end

end
36 changes: 19 additions & 17 deletions lib/puppet/provider/wsuspatchstatus/wsuspatchstatus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,45 @@
'powershell.exe'
end

@@connstr= "import-module poshwsus | out-null; $null=(Connect-PoshWSUSServer localhost -port 8530)"

def connectstring
"import-module poshwsus | out-null; $null=(Connect-PoshWSUSServer localhost -port 8530)"
end

def exists?

kbnumber = @resource[:patch].sub(/kb/,'')
kbnumber = @resource[:name].sub(/kb/,'')
#poshregex='('+(@resource[:wsusgroups].join(',')).gsub(',',')|(')+')'

args = "#{@@connstr};(Get-PoshWSUSUpdateApproval | Where-Object {$_.updatekb -eq \"#{kbnumber}\"} | Sort-Object -Property TargetGroup -Unique).Targetgroup"
approvals=poshexec(args).to_a
approvals.map {|x| x.chomp!}
extraneous = @resource[:wsusgroups] - approvals
connstr = connectstring
args = "#{connstr};(Get-PoshWSUSUpdateApproval | Where-Object {$_.updatekb -eq \"#{kbnumber}\"} | Sort-Object -Property TargetGroup -Unique).Targetgroup"
approvals=Array(poshexec(args))
approvals.map {|x| x.chomp!}
extraneous = @resource[:wsusgroups] - approvals
return true if extraneous.empty?
end

def wsusgroups
kbnumber = @resource[:patch].sub(/kb/,'')
args = "#{@@connstr};(Get-PoshWSUSUpdateApproval | Where-Object {$_.updatekb -eq \"#{kbnumber}\"} | Sort-Object -Property TargetGroup -Unique).Targetgroup"
approvals=poshexec(args).to_a
kbnumber = @resource[:name].sub(/kb/,'')
connstr = connectstring
args = "#{connstr};(Get-PoshWSUSUpdateApproval | Where-Object {$_.updatekb -eq \"#{kbnumber}\"} | Sort-Object -Property TargetGroup -Unique).Targetgroup"
approvals=Array(poshexec(args))
approvals.map {|x| x.chomp!}
return approvals
end

def wsusgroups=(newvalue)
kbnumber = @resource[:patch].sub(/kb/,'')
kbnumber = @resource[:name].sub(/kb/,'')
connstr = connectstring
newvalue.each { |wsusgroup|
args = "#{@@connstr};Approve-PoshWSUSUpdate -Group \"#{wsusgroup}\" -Update \"#{kbnumber}\" -Action Install"
args = "#{connstr};Approve-PoshWSUSUpdate -Group \"#{wsusgroup}\" -Update \"#{kbnumber}\" -Action Install"
poshexec(args)
}
end

def create
self.wsusgroups = @resource[:wsusgroups]
end

def destroy
kbnumber = @resource[:patch].sub(/kb/,'')
kbnumber = @resource[:name].sub(/kb/,'')
@resource[:wsusgroups].each { |wsusgroup|
args = "#{@@connstr};Approve-PoshWSUSUpdate -Group \"#{wsusgroup}\" -Update \"#{kbnumber}\" -Action Removal"
poshexec(args)
Expand Down

0 comments on commit 456d11e

Please sign in to comment.