Skip to content
Browse files

Hunter's improvements and the real apply script

Warning if file doesn't exist
uniq duplicate file sources
defaulted the node for the script if none is specified
  • Loading branch information...
1 parent d7065bb commit 36482363e9742cf53f7dfa0accbb0b6122ee54c9 Matt Robinson committed
View
18 apply_compiled_catalog_tarball.rb
@@ -1,14 +1,10 @@
#!/usr/bin/ruby
-require 'getoptlong'
-opts = GetoptLong.new(
- [ '--node', '-n', GetoptLong::REQUIRED_ARGUMENT ]
-)
-node = nil
-opts.each do |opt, arg|
- case opt
- when '--node'
- node = arg
- end
-end
+nodefile = ARGV[0]
+nodefile =~ /(.*)\.compiled_catalog_with_files/
+nodename = $1
+`tar -xvPf #{nodefile}`
+modulepath = File.open("#{nodename}.modulepath").readlines.first
+
+`puppet --debug --apply #{nodename}.catalog.pson --modulepath #{modulepath}`
View
15 compile_with_files.rb
@@ -1,14 +1,14 @@
-#!/usr/bin/ruby
+#!/usr/bin/env ruby
require 'getoptlong'
opts = GetoptLong.new(
- [ '--node', '-n', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--node', '-n', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--modulepath', '-m', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--external_nodes', '-e', GetoptLong::OPTIONAL_ARGUMENT ]
)
require 'puppet'
-node, external_nodes, modulepath = nil, nil, Puppet[:modulepath]
+node, external_nodes, modulepath = 'default', nil, Puppet[:modulepath]
opts.each do |opt, arg|
case opt
when '--node'
@@ -43,9 +43,14 @@
paths = compiled_catalog.vertices.
select {|vertex| vertex.type == "File" and vertex[:source] =~ %r{puppet://}}.
- map {|file_resource| Puppet::FileServing::Metadata.find(file_resource[:source])}. # this step should return nil where source doesn't exist
+ map do |file_resource|
+ file_metadata = Puppet::FileServing::Metadata.find(file_resource[:source])
+ puts "The file #{file_resource[:source]} is not accessible" if file_metadata.nil?
+ file_metadata
+ end.
compact.
- map {|filemetadata| filemetadata.path}
+ map {|filemetadata| filemetadata.path}.
+ uniq
rescue => detail
$stderr.puts detail
View
BIN default.compiled_catalog_with_files.tar.gz
Binary file not shown.
View
BIN whatever.compiled_catalog_with_files.tar.gz
Binary file not shown.

0 comments on commit 3648236

Please sign in to comment.
Something went wrong with that request. Please try again.