Luckily, custom facts and functions are quick and easy to write yourself.
This blog will focus on how to extend Puppet beyond the built-in functionality.
Once the functions have been synchronized, they can be referenced from the Puppet manifests.
There is one important thing to remember about how functions are executed.
Let’s create a new module for functions with the following set of commands: Now that we have created a module to store our custom functions, we can write our first function.
Let’s create a function called cli_command, which accepts a command-line command as an argument, executes the command, and returns the results.Here is the content of the cli_command function: As I mentioned earlier, Puppet functions are executed either on the Puppet Agent or on the Puppet Master, depending on whether the Agent is run against the Puppet Master.Let’s test our new cli_command function in standalone mode without the Puppet Master, before we try running it on the Puppet Master, and then compare the results from the function.Open the manifests/file and add a line include flib to the ‘web.development.vm’ block.To make the Puppet report shorter, I’ve also commented out the include statements for the other classes associated with the web.node.We now have enough evidence to show that the functions can be run on the Puppet Agent and on the Puppet Master nodes, depending on the mode the Puppet Agent runs on.Let’s move on and write a function that distributes the file content across the environment.To decide whether we want the function to run on the Puppet Agent or on the Master, we must have a class that calls the function.Open flib/manifests/init.pp, and replace the content generated by the puppet module generate command with the following four lines: Once the file has been saved, then we can try to apply the flib class to the web server node.Log on to the Web Server node (with the username root and password puppet), and run the following two commands: Next, we can try to apply the flib class to the Puppet Agent against the Puppet Master.In order to apply the class, we must include it in the Agent’s catalog, which is defined in the manifests/file.