Search code examples
puppetirb

How to use irb to test/debug in puppet


I'm on puppet 3.6.2, I have the source for our puppet repo. I want to do this:

irb> require 'rubygems'
irb> require 'puppet'
irb> Puppet[:confdir] = "/home/wwalker/git/puppet"
irb> node=Puppet::Node.new('localhost')
irb> compiler=Puppet::Parser::Compiler.new(node)
irb> scope=Puppet::Parser::Scope.new(compiler)
irb> scope.function_generate_mysql_url(...)

However, I can't get past the compiler:

irb(main):010:0> compiler=Puppet::Parser::Compiler.new(node) Puppet::Context::UndefinedBindingError:
     no 'environments' in
     {:current_environment=><Puppet::Node::Environment:17836720 @name="*root*" @manifest="no_manifest" @modulepath="" >,
      :root_environment=><Puppet::Node::Environment:17836720 @name="*root*" @manifest="no_manifest" @modulepath="" >}
     at top of [[0, nil, nil]]

I assume I need to set the "environment", or I've set confdir wrong.

Anyone else done any testing of puppet modules in irb?

I do not have direct access to the puppet server. I've tried this on my workstation (puppet-server 4.1 installed) and on a client (puppet 3.6.2 installed).

This seems so simple, but I'm clearly missing something.

Anyone know what step(s) I'm missing?


Solution

  • I am not really sure what you are trying to accomplish but there is a puppet debugger repl for the puppet language which is very similar to pry/irb but specific to puppet.

    https://github.com/nwops/puppet-debugger

    You can use the debugger to run any function currently available in your module path among many other features.

    You can also set a breakpoint in your puppet code and have it load the debugger using the 'debug::break()' function.

    Ruby Version: 2.0.0
    Puppet Version: 4.9.4
    Puppet Debugger Version: 0.6.0
    Created by: NWOps
    Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "classes",
         "play", "classification", "types", "datatypes", "reset", or "help" for more information.
    
    1:>> md5('sdafsd')
     => "569ebc3d91672e7d3dce25de1684d0c9"
    2:>>