Class: R10kResolve
- Inherits:
-
Object
- Object
- R10kResolve
- Defined in:
- lib/r10k-resolve.rb,
lib/r10k-resolve/version.rb
Constant Summary collapse
- VERSION =
'0.0.2'
Instance Attribute Summary collapse
-
#dryrun ⇒ Object
Returns the value of attribute dryrun.
-
#force ⇒ Object
Returns the value of attribute force.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#output ⇒ Object
Returns the value of attribute output.
-
#puppetversion ⇒ Object
Returns the value of attribute puppetversion.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ R10kResolve
constructor
A new instance of R10kResolve.
- #resolve ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ R10kResolve
Returns a new instance of R10kResolve.
8 9 10 11 12 13 14 |
# File 'lib/r10k-resolve.rb', line 8 def initialize( = {}) [:source, :output, :puppetversion, :force, :dryrun, :logger].each do |key| send("#{key}=", [key]) end @output = File.open(@output, 'w+') if @output.is_a? String end |
Instance Attribute Details
#dryrun ⇒ Object
Returns the value of attribute dryrun.
6 7 8 |
# File 'lib/r10k-resolve.rb', line 6 def dryrun @dryrun end |
#force ⇒ Object
Returns the value of attribute force.
6 7 8 |
# File 'lib/r10k-resolve.rb', line 6 def force @force end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/r10k-resolve.rb', line 6 def logger @logger end |
#output ⇒ Object
Returns the value of attribute output.
6 7 8 |
# File 'lib/r10k-resolve.rb', line 6 def output @output end |
#puppetversion ⇒ Object
Returns the value of attribute puppetversion.
6 7 8 |
# File 'lib/r10k-resolve.rb', line 6 def puppetversion @puppetversion end |
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/r10k-resolve.rb', line 6 def source @source end |
Instance Method Details
#resolve ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/r10k-resolve.rb', line 16 def resolve content = File.read(@source) puppetfile = PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content) # Make sure the Puppetfile is valid unless puppetfile.valid? logger.error("Puppetfile source is not valid") puppetfile.validation_errors.each { |err| logger.error(err) } return false end resolver = PuppetfileResolver::Resolver.new(puppetfile, puppetversion) result = resolver.resolve(strict_mode: true) # Output resolution validation information result.validation_errors.each { |err| logger.info(err) } logger.info('Generating Puppetfile...') # copy over the existing Puppetfile, then add resolved dependencies below @output.write(puppetfile.content) @output.write("\n####### resolved dependencies #######\n") result.dependency_graph.each do |dep| # ignore the original modules, they're already in the output next if puppetfile.modules.find { |mod| mod.name == dep.name } mod = dep.payload next unless mod.is_a?(PuppetfileResolver::Models::ModuleSpecification) @output.write("mod '#{dep.payload.owner}-#{dep.payload.name}', '#{dep.payload.version}'\n") end @output.write("\n# Generated with r10k-resolve v#{R10kResolve::VERSION}") @output.write(" for Puppet v#{puppetversion}") if puppetversion @output.write("\n\n") logger.warn( "Please inspect the output to ensure you know what you are deploying in your infrastructure." ) end |