Ask Your Question
0

Debug in Custom Function

asked 2017-10-24 10:33:31 -0600

annihil8ted gravatar image

updated 2017-11-14 12:24:17 -0600

I have a custom function that doesn't seem to output any debug messages. I can run puppet agent -t --debug but nothing comes up. I do get other debug messages though. Here's my custom function:

module Puppet::Parser::Functions
  newfunction(:passsec_base, :type => :rvalue) do |*args|
    Puppet.debug('start passsec base')
  end
end

I've also done debug ('start passec base') but it just doesn't seem to output anywhere. This is on my client and I initiate runs from the client.

If I use puts 'start passsec base', I'll get a log output but I would really like to use the debug method if it's possible.

edit retag flag offensive close merge delete

Comments

Do you _call_ your function anywhere? Also, I guess Puppet.debug() logs to the evaluating process, i.e. the master.

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-24 15:49:59 -0600 )edit

Yea I call my function in a normal .pp file. I've checked the logs of master and only puts will log anything.

annihil8ted gravatar imageannihil8ted ( 2017-10-24 16:02:37 -0600 )edit

I hope, i didn't have to mention to start the master with `log_level = debug` then. You did so, didn't you?

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-24 18:11:17 -0600 )edit

Yes I have enabled log_level = debug. I ended up just using puts and debugging it that way.

annihil8ted gravatar imageannihil8ted ( 2017-11-14 12:24:59 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-10-25 03:53:47 -0600

David Schmitt gravatar image

If it's any help for you, this worked for me:

david@davids:/tmp$ pdk new module passsec
pdk (INFO): Creating new module: passsec

We need to create a metadata.json file for this module, so we're going to ask you 9 questions.
If the question is not applicable to this module, accept the default option shown after each question. You can modify any answers at any time by manually updating the metadata.json file.

[Q 1/9] If you have a Puppet Forge username, add it here.
We can use this to upload your module to the Forge when it's complete.
--> (david) pdk (INFO): Interview cancelled; not generating the module.
david@davids:/tmp$ pdk new module passsec --skip-interview
pdk (INFO): Creating new module: passsec
pdk (INFO): Module 'passsec' generated at path '/tmp/passsec'.
pdk (INFO): In your module directory, add classes with the 'pdk new class' command.
david@davids:/tmp$ cd passsec/
david@davids:/tmp/passsec$ mkdir -p lib/puppet/parser/functions
david@davids:/tmp/passsec$ vi lib/puppet/parser/functions/passsec_base.rb
david@davids:/tmp/passsec$ pdk validate ruby lib/puppet/parser/functions/passsec_base.rb 
[✖] Checking Ruby code style (**/**.rb).
convention: rubocop: lib/puppet/parser/functions/passsec_base.rb:1:1: Missing top-level module documentation comment.
convention: rubocop: lib/puppet/parser/functions/passsec_base.rb:2:30: Use the new Ruby 1.9 hash syntax.
warning: rubocop: lib/puppet/parser/functions/passsec_base.rb:2:53: Unused block argument - `args`. You can omit the argument if you don't care about it.
convention: rubocop: lib/puppet/parser/functions/passsec_base.rb:6:1: 1 trailing blank lines detected.
david@davids:/tmp/passsec$ pdk bundle exec -- puppet apply --libdir ./lib --debug -e 'passsec_base()'
Debug: Runtime environment: puppet_version=5.3.2, ruby_version=2.1.9, run_mode=user, default_encoding=UTF-8
[...]
Debug: Caching environment 'production' (ttl = 0 sec)
Debug: start passsec base
Notice: Compiled catalog for davids.corp.puppetlabs.net in environment production in 0.02 seconds
[...]
david@davids:/tmp/passsec$ 

Note the use of puppet apply to get a minimal test environment, and specifying --libdir ./lib to get it to load the correct code.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-10-24 10:33:31 -0600

Seen: 274 times

Last updated: Nov 14