summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/provider')
-rw-r--r--lib/puppet/provider/package_manifest/flat_file.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/puppet/provider/package_manifest/flat_file.rb b/lib/puppet/provider/package_manifest/flat_file.rb
new file mode 100644
index 0000000..96e033b
--- /dev/null
+++ b/lib/puppet/provider/package_manifest/flat_file.rb
@@ -0,0 +1,39 @@
+
+require 'set'
+
+
+Puppet::Type.type(:package_manifest).provide(:flat_file) do
+
+ desc "Write package manifest to a flat file"
+
+ def exists?
+ # exists? is always run before create, so we can create package list here
+ @packages = resource.catalog.resources.collect { |r|
+ r.name if r.type == :package
+ }.compact.sort
+
+ exists = File.exist?(resource[:path])
+ if exists
+ new_content = Set.new @packages
+ old_content = Set.new(
+ File.open(resource[:path], 'r').each_line.collect{ |pkg| pkg.strip() }
+ )
+ exists = new_content == old_content
+ end
+ exists
+ end
+
+ def create
+ FileUtils.mkdir_p(File.dirname(resource[:path]))
+ File.open(resource[:path], 'w') do |f|
+ @packages.each do |pkg_name|
+ f.puts(pkg_name)
+ end
+ end
+ end
+
+ def destroy
+ File.delete(resource[:path])
+ end
+
+end