Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Sample usage file doesn't work #7

Closed
threepistons opened this issue Jun 3, 2020 · 3 comments · Fixed by #8
Closed

Sample usage file doesn't work #7

threepistons opened this issue Jun 3, 2020 · 3 comments · Fixed by #8

Comments

@threepistons
Copy link

Given: Debian 10.4, Ruby 2.5.5p157, puppetfile-resolver 0.2.0 installed using gem install puppetfile-resolver --user-install

When I: put the full path to my Puppetfile in the puppetfile_path variable on the top line of the sample usage file and save it as puppetfile-resolver.rb, and then run ruby puppetfile-resolver.rb

I get:

-> % ruby puppetfile-resolver.rb
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/all/specifications/erubis-2.7.0.gemspec:16.
Traceback (most recent call last):
puppetfile-resolver.rb:18:in `<main>': uninitialized constant PuppetfileResolver::Resolver (NameError)

I expected: something else a bit more useful, not sure what because I've not got this to work for me yet.

@threepistons
Copy link
Author

I added require 'puppetfile-resolver/resolver' immediately above resolver = PuppetfileResolver::Resolver.new(puppetfile, nil) and now have a raft of "Resolution Validation Error: foo: could not find module bar/foo" messages.

@threepistons
Copy link
Author

Resolution: error in sample code

What worked for me is:

puppetfile_path = '/path/to/my/Puppetfile'

# Parse the Puppetfile into an object model
content = File.open(puppetfile_path, 'rb') { |f| f.read }
require 'puppetfile-resolver' ## Note: not just the R10KEval bit, the whole gem
puppetfile = ::PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content)

# Make sure the Puppetfile is valid
unless puppetfile.valid?
  puts 'Puppetfile is not valid'
  puppetfile.validation_errors.each { |err| puts err }
  exit 1
end

# Create the resolver
# - Use the document we just parsed (puppetfile)
# - Don't restrict by Puppet version (nil)
resolver = PuppetfileResolver::Resolver.new(puppetfile, nil)

# Configure the resolver
cache                 = nil  # Use the default inmemory cache
ui                    = nil  # Don't output any information
module_paths          = []   # List of paths to search for modules on the local filesystem
allow_missing_modules = true # Allow missing dependencies to be resolved
opts = { cache: cache, ui: ui, module_paths: module_paths, allow_missing_modules: allow_missing_modules }

# Resolve
result = resolver.resolve(opts)

# Output resolution validation errors
result.validation_errors.each { |err| puts "Resolution Validation Error: #{err}\n"}

This gave me the following useful output:

-> % ruby puppetfile-resolver.rb                                                                        
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /usr/share/rubygems-integration/all/specifications/erubis-2.7.0.gemspec:16.
Traceback (most recent call last):
        10: from puppetfile-resolver.rb:28:in `<main>'
         9: from /home/threepistons/.gem/ruby/2.5.0/gems/puppetfile-resolver-0.2.0/lib/puppetfile-resolver/resolver.rb:36:in `resolve'
         8: from /home/threepistons/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolver.rb:43:in `resolve'
         7: from /home/threepistons/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:182:in `resolve'
         6: from /home/threepistons/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:254:in `process_topmost_state'
         5: from /home/threepistons/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:673:in `attempt_to_activate'
         4: from /home/threepistons/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:702:in `attempt_to_filter_existing_spec'
         3: from /home/threepistons/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:308:in `unwind_for_conflict'
         2: from /home/threepistons/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:308:in `tap'
         1: from /home/threepistons/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:310:in `block in unwind_for_conflict'
/home/nhg45/.gem/ruby/2.5.0/gems/molinillo-0.6.6/lib/molinillo/resolution.rb:328:in `raise_error_unless_state': Puppetfile Resolver could not find compatible versions for possibility named "apt": (PuppetfileResolver::Puppetfile::DocumentVersionConflictError)
  In Puppetfile:
    puppetlabs-apt =5.0.0

    puppet-unattended_upgrades =3.1.0 was resolved to Forge puppet-unattended_upgrades-3.1.0, which depends on
      puppetlabs-apt >= 2.2.0 < 5.0.0

glennsarti added a commit that referenced this issue Jun 4, 2020
There was a missing require in the example usage due to using bundle versus a
gem install.  This commit also updates the yard documentation.
@glennsarti
Copy link
Owner

Thanks @threepistons ! Yes you're right. My example assumed it would be used in a bundle instead of gem install. Thankyou for quick fix. The documentation will be updated shortly.

glennsarti added a commit that referenced this issue Jun 4, 2020
logicminds pushed a commit to nwops/puppetfile-resolver that referenced this issue Jul 3, 2020
There was a missing require in the example usage due to using bundle versus a
gem install.  This commit also updates the yard documentation.
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants