Skip to content

Commit 14e857e

Browse files
committed
rework, now gets state during run as it may change from other sources
1 parent 9abf756 commit 14e857e

File tree

1 file changed

+28
-22
lines changed
  • lib/puppet/provider/profile_manager

1 file changed

+28
-22
lines changed

lib/puppet/provider/profile_manager/macos.rb

+28-22
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,29 @@ def exists?
2222
# if already installed, check if it is the right one.
2323
# if not installed, return false.
2424
# if we are removing, don't care if it is the right one.
25-
if Facter.value(:profiles).include? resource[:name]
25+
state = getinstalledstate
26+
if state != false
2627
if resource[:ensure] == :absent
2728
return true
2829
else
29-
return current
30+
begin
31+
return state['install_date'].to_time == getreceipts[resource[:name]]['install_date']
32+
rescue NoMethodError
33+
# no matching receipt
34+
return false
35+
end
3036
end
3137
else
3238
return false
3339
end
3440
end
3541

36-
def getinstalleddate
37-
# must be rerun as the output from Facter's earlier run is now
38-
# outdated, but this only runs on refresh so not horrible.
39-
output = Puppet::Util::Execution.execute('/usr/sbin/system_profiler SPConfigurationProfileDataType -xml')
40-
41-
for item in Puppet::Util::Plist.parse_plist(output)[0]['_items'][0]['_items']
42-
if item['spconfigprofile_profile_identifier'] == resource[:name]
43-
return DateTime.parse(item['spconfigprofile_install_date'].scan(/\(([^\)]+)\)/).last.first)
44-
end
45-
end
46-
end
47-
4842
def getreceipts
4943
begin
50-
receipts = Puppet::Util::Plist.read_plist_file(Facter.value(:puppet_vardir) + '/mobileconfigs/receipts.plist')
44+
receipts = Puppet::Util::Plist.read_plist_file(Puppet[:vardir] + '/mobileconfigs/receipts.plist')
5145
rescue IOError, Errno::ENOENT
5246
receipts = {}
5347
end
54-
5548
receipts
5649
end
5750

@@ -61,15 +54,28 @@ def writereceipt
6154
# code from the fact but needs to re-run immediately.
6255
receipts = getreceipts
6356

64-
receipts[resource[:name]] = { 'install_date' => getinstalleddate }
57+
receipts[resource[:name]] = { 'install_date' => getinstalledstate['install_date'] }
6558

66-
Puppet::Util::Plist.write_plist_file(receipts, Facter.value(:puppet_vardir) + '/mobileconfigs/receipts.plist')
59+
Puppet::Util::Plist.write_plist_file(receipts, Puppet[:vardir] + '/mobileconfigs/receipts.plist')
6760
end
6861

69-
def current
70-
return getinstalleddate.to_time == getreceipts[resource[:name]]['install_date']
71-
rescue NoMethodError
72-
# no matching receipt
62+
def getinstalledstate
63+
output = Puppet::Util::Execution.execute('/usr/sbin/system_profiler SPConfigurationProfileDataType -xml')
64+
65+
data = Puppet::Util::Plist.parse_plist(output)[0]['_items']
66+
67+
unless data.empty?
68+
for item in data[0]['_items']
69+
if item['spconfigprofile_profile_identifier'] == resource[:name]
70+
return {
71+
'identifier' => item['spconfigprofile_profile_identifier'],
72+
'display_name' => item['_name'],
73+
'uuid' => item['spconfigprofile_profile_uuid'],
74+
'install_date' => DateTime.parse(item['spconfigprofile_install_date'].scan(/\(([^\)]+)\)/).last.first)
75+
}
76+
end
77+
end
78+
end
7379
return false
7480
end
7581
end

0 commit comments

Comments
 (0)