Table of contents
1.
💤Introduction
2.
💤Developer debugging
2.1.
👤Debugging Clojure Code
2.2.
👤Debugging Ruby Code
2.3.
👤Ruby REPL incompatible with Lein REPL
2.4.
👤ruby-debug
2.4.1.
🌞Installation
2.4.2.
🌞Usage
2.5.
👤Pry
2.5.1.
🌞Installation
2.5.2.
🌞Usage
2.6.
👤Limitations
3.
💤Running from source
3.1.
You’ll need to follow the below steps specified to run Puppet Server from source:
3.2.
Installing Prerequisites
3.3.
Cloning Git repository and setting up Working Tree
3.4.
The simplest method to this is to run:
3.5.
Running the server from the clojure REPL.
3.6.
Running the server from the command line
3.7.
Development environment gotchas
4.
💤Tracing Code events
5.
💤Frequently Asked Questions
5.1.
How do you create a custom fact in Puppet?
5.2.
How do you identify Puppet facts?
5.3.
What are the primary components of Puppet architecture?
5.4.
What is puppet software used for?
6.
💤Conclusion
Last Updated: Mar 27, 2024
Hard

Developer Information In Puppet

Author Manshi
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

💤Introduction

In this article we will learn about Developer information in Puppet. It is a system management tool that centralizes and automates configuration management. Puppet can also be used to deploy software. It is open-source configuration management , that is widely used for server configuration, management, deployment, and orchestration of various applications and services across an organization's entire infrastructure.

introductory img

Let’s Start!

💤Developer debugging

As Puppet Server runs both Clojure and Ruby code, debugging approaches vary depending on which part of the application we are interested in.

debugger

👤Debugging Clojure Code

There are numerous options for debugging the web service layer or other Clojure-written parts of the app. The Clojure REPL is frequently the most useful tool because it makes interacting with individual functions and namespaces so simple.

There are numerous options for more traditional debugging capabilities, such as defining breakpoints and stepping through the lines of your source code. To some extent, any Java debugging tool will work, but Clojure-specific tools like CDT and debug-repl will integrate better with your Clojure source files.

👤Debugging Ruby Code

Debugging Ruby code in Puppet Server can be more difficult because Java and Clojure debugging tools will only take you into the JRuby interpreter source code, not the Ruby code that it is processing. So, if you want to debug Ruby code directly, you'll need to install gems and use their capabilities.

👤Ruby REPL incompatible with Lein REPL

Please keep in mind that a Ruby REPL is incompatible with lein repl because JRuby does not accept data from standard input when running inside of lein repl. To use a ruby REPL while developing, start puppetserver from source with lein run rather than lein repl:

$ lein run --config ~/.puppetserver/puppetserver.conf


The lein run command will start the server normally in the foreground. When the relevant statement is reached, pry or ruby-debug will display an input prompt. In contrast to lein repl, which displays a prompt early in the process lifecycle, expect to see the normal lein run output followed by the Ruby REPL. In this sense, the "ruby repl" is more of a breakpoint than a Clojure REPL.

👤ruby-debug

ruby-debug

🌞Installation

There are numerous gems available that provide different methods of debugging Ruby code depending on the version of Ruby and the Ruby interpreter you're using. Ruby-debug is a popular gem, and there is a JRuby-compatible version available. Run the following command to install it for use in Puppet Server:

$ sudo puppetserver gem install ruby-debug

 

Alternatively, if you're running puppetserver from source:

$ lein gem -c /path/to/puppetserver.conf install ruby-debug

🌞Usage

After installing the gem, you can invoke the debugger by adding the following line to any Ruby code running in Puppet Server (including the Puppet Ruby code):

require 'ruby-debug'; debugger

👤Pry

🌞Installation

Pry is another well-known gem for inspecting Ruby code. It is JRuby-compatible. Install pry when running a packaged version of puppetserver by doing the following:

$ sudo puppetserver gem install pry --no-ri --no-rdoc

 

Alternatively, if you're running puppetserver from source:

$ lein gem -c ~/puppetserver/puppetserver.conf -- install pry \
  --no-ri --no-rdoc

🌞Usage

To use the pry repl, puppetserver should be running in the foreground. The puppet foreground subcommand is used to stop the background service and start the server in the foreground:

$ sudo service puppetserver stop
$ sudo puppetserver foreground

 

After installing, add the following line to the Ruby code:

require 'pry'; binding.pry

This will display an advanced interactive REPL at the line of code where pry was called.

👤Limitations

We are aware that some popular ruby debugging gems/tools/features do not currently work with JRuby/Puppet Server. It's important to us that the Ruby developer experience isn't hampered for developers who use Puppet Server rather than webrick, so if you run into problems like this, please file an issue on our Bug Tracker, and we'll see if we can add support for what we're missing. 

In many cases, it may be as simple as submitting a JRuby patch or a JRuby-compatibility patch for an existing gem, and we are eager to assist with such requests whenever possible.

💤Running from source

You’ll need to follow the below steps specified to run Puppet Server from source:

# clone git repository and initialize submodules
$ git clone --recursive git://github.com/puppetlabs/puppetserver
$ cd puppetserver

# Remove any old config if you want to make sure you're using the latest
# defaults
$ rm -rf ~/.puppetserver

# Run the `dev-setup` script to initialize all required configuration
$ ./dev-setup

# Launch the clojure REPL
$ lein repl
# Run Puppet Server
dev-tools=> (go)
dev-tools=> (help)

You can run the agent in another shell:
# Go to the directory where you checked out puppetserver
$ cd puppetserver
# Set ruby and bin paths
$ export RUBYLIB=./ruby/puppet/lib:./ruby/facter/lib
$ export PATH=./ruby/puppet/bin:./ruby/facter/bin:$PATH
# Run the agent
$ puppet agent -t

Installing Prerequisites

Make sure the following prerequisites are installed using your system's package tools:

  • JDK 1.8 or Java 11
  • Leiningen 2.9.1 (latest)
  • Git (for checking out the source code)

Cloning Git repository and setting up Working Tree

$ git clone --recursive
git://github.com/puppetlabs/puppetserver
$ cd puppetserver

The simplest method to this is to run:

$ ./dev-setup

 

This will create all of the configuration files and directories in your /.puppetlabs directory. If you want to see what all of the default file paths are, look in./dev/puppetserver.conf.

The default paths should all match the default values used by puppet (for non-root users).

Running the server from the clojure REPL.

The clojure REPL is the primary technique for starting the server for development purposes. The git repo includes certain files in the /dev directory that are meant to aid in this procedure.

When running a clojure REPL with the lein repl command-line command, lein will load the dev/dev-tools.clj namespace by default.

When running the server inside the clojure REPL, you can make changes to the source code and reload the server without restarting the entire JVM. It can be significantly faster than running from the command line while undertaking iterative development.

Run the following commands to start the server from the REPL:

$ lein repl
nREPL server getting started on port 58321 on host 117.0.0.1
dev-tools=> (go)
dev-tools=> (help)
If you make changes to the source code, all you have to do to restart the server with the most recent changes is:
dev-tools=> (reset)

 

Restarting the server this way should be significantly faster than restarting the entire JVM process.

Running the server from the command line

If you don't want to run the server interactively in the REPL, you can start it as a regular process. Simply run the following command to start the Puppet Server when running from source:

$ lein run -c /path/to/puppetserver.conf

Development environment gotchas

Missing git submodules

If you receive the following error:

Execution error (LoadError) at org.jruby.RubyKernel/require
(org/jruby/RubyKernel.java:970).
(LoadError) no such file to load -- puppet

 

Then you most likely forgot to fetch the git submodules.

Failing tests

If you change the:webserver:ssl-port configuration option from its default value of 8140, tests will fail with the following errors:

lein test :only puppetlabs.general-puppet.general-puppet-int-test/test-external-command-execution

ERROR in (test-external-command-execution) (SocketChannelImpl.java:-2)
Uncaught exception, not in assertion.
expected: nil 2019-02-06 14:58:50,541 WARN  [async-dispatch-18] [o.e.j.s.h.ContextHandler] Empty contextPath
actual: java.net.ConnectException: Connection refused at sun.nio.ch.SocketChannelImpl.checkConnect (SocketChannelImpl.java:-2) 
sun.nio.ch.SocketChannelImpl.finishConnect (SocketChannelImpl.java:717)

org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent (DefaultConnectingIOReactor.java:171)

org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents (DefaultConnectingIOReactor.java:145) 

org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute (AbstractMultiworkerIOReactor.java:348)

org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute (PoolingNHttpClientConnectionManager.java:192)

org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run (CloseableHttpAsyncClientBase.java:64)    java.lang.Thread.run (Thread.java:844)

 

Returning the ssl-port variable to 8140 allows the tests to run normally.

💤Tracing Code events

For tracing code events, such as lines of code being executed and calls to C-language routines or Ruby methods, the JRuby runtime supports the Ruby set trace func Kernel method. This can also be used for tracing in Puppet Server.

To enable more verbose tracing, such as capturing lower-level calls into C code, set the jruby.debug.fullTrace Java property to "true." If you are running Puppet Server from the source, add the following option to the project.clj file:

:jvm-opts ["-Djruby.debug.fullTrace=true"]

If you are running Puppet Server from a package, add the following option to the puppetserver file in /etc/sysconfig or /etc/default, depending on your operating system distribution:

JAVA_ARGS="-Xms2g -Xmx2g -Djruby.debug.fullTrace=true"

A call to the set trace func function can be made in one of the Puppet Server code's Ruby files. One common place to put this call for the trace to be in effect for the full execution of Ruby code would be at the top of the../src/ruby/puppetserver-lib/puppet/server/master.rb file, which configures Ruby Puppet for running inside Puppet Server. A simple implementation could look like this:

     set_trace_func proc { 
        |event, file, line, id, binding, classname|
        printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
     }

Output from set_trace_func looks like the following:

 c-call /usr/share/puppetserver/puppet-server-release.jar!/META-INF/jruby.home/lib/ruby/shared/jopenssl19/openssl/ssl-internal.rb:30 initialize OpenSSL::X509::Store

 

Check out most important Git Interview Questions here.

💤Frequently Asked Questions

How do you create a custom fact in Puppet?

Custom facts can be added to the main Puppet server by writing snippets of Ruby code. Puppet then distributes the facts to the client via plug-ins in modules.

How do you identify Puppet facts?

Run facter -p on the command line to see a node's fact values, or browse facts on node detail pages in the Puppet Enterprise console.

What are the primary components of Puppet architecture?

The components include Puppet Server, Puppet agent, Facter, Hiera, and PuppetDB. 

What is puppet software used for?

Puppet is a software configuration management and deployment tool that is open source. It is most commonly used on Linux and Windows to simultaneously pull the strings on multiple application servers.

💤Conclusion

In this article, we discussed developer information in Puppet software. We covered topics like Developer debugging, Running from source, and Code events tracing deeply.

Want To Learn More About brand-new technologies? We Have A Whole Category, visit Coding Ninjas or explore yourself in the following links:

Data Structures and Algorithms

Competitive Programming

Learn Java

Web technologies

Mobile technologies

Interview Questions

Interview Puzzles

Node.Js Web applications

Communications Skills

Aptitude

Live masterclass