Table of contents
1.
Introduction
2.
Grouping and Classifying Nodes
2.1.
Working of Node Group Inheritance
2.2.
Best Practices for Classifying Node Groups
2.3.
Environment vs Classification Node Groups
2.4.
Create Node Groups
2.5.
Add nodes to Node Group
2.6.
Statically add nodes to a node group
2.7.
Dynamically add nodes to a node group
2.8.
Writing Node Group Rules
2.9.
Using Structured and Trusted Facts for Node Group Rules
2.10.
Declare Classes
2.11.
Enable Data Editing in the Console
2.12.
Define Data Used by Node Groups
2.13.
View Nodes in a Node Group
3.
Making changes to node groups
3.1.
Edit or Remove Node Groups
3.2.
Remove Nodes from a Node Group
4.
Environment Based Testing
4.1.
Test and Promote a Parameter
4.2.
Test and Promote a Class
4.3.
Test Code with Canary Nodes and Alternate Puppet Environments
5.
Preconfigured Node Groups
5.1.
All Nodes Node Group
5.2.
Infrastructure Node Groups
5.3.
PE Patch Management Node Group
5.4.
Environment Node Groups
6.
Managing Windows Nodes
6.1.
Manage Windows Services
6.2.
Manage Windows Users and Groups
6.3.
Using Windows Modules
7.
Frequently Asked Questions
7.1.
How is Puppet different from Ansible?
7.2.
What exactly is a Puppet production environment?
7.3.
On a puppet agent, where are environments specified?
8.
Conclusion
Last Updated: Mar 27, 2024
Medium

Advanced Concept of Managing Nodes in Puppet

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

Introduction

Hello Ninja, managing software configs can make us a bit tired sometimes, doesn’t it? For this reason, we will look into Puppet today. You can definitely play with this Puppet, but only inside your computers. On Linux and Windows, it's most typically used to pull the strings on numerous application servers simultaneously. 

Puppet is a software configuration management and deployment solution that is free and open source. However, Puppet may also be used on a variety of platforms, such as IBM mainframes, Cisco routers, and Mac OS servers. In the article, we will read about the advanced concept of Managing nodes in Puppet.

Advanced Concept of Managing Nodes in Puppet

Grouping and Classifying Nodes

Assign variables, parameters, and classes to nodes to configure them. It is known as classification.

To categorise nodes, we must:

1. Make node groups that contain nodes and preferences (variables, parameters, and classes) that we want to apply to the group's nodes.

2. Add nodes to the groups.

3. Declare classes and define the data that the node groups will use. Enabling data editing in the console may be required.

Nodes can be members of several node groups, and they inherit variables, class parameters and classes from all of them.

We can see nodes in a node group and Make modifications to node groups after classifying nodes.

Working of Node Group Inheritance

The hierarchy of node groupings is parent-child-grandchild. When nodes get introduced to a group, they inherit classes, parameters, variables, and rules from the group's ancestors as well as their immediate node group.

Classes: When a class gets declared in an ancestor node group, it gets implicitly declared in all node groups that descend from that group.

Class parameters and variables: Unless a different value gets set in a descendant node group, successor node groups inherit variables and class parameters from ancestors.

Dynamic node group rules: To be part of a group, a node must meet all of the rules in the immediate group and the rules in the ancestral groups.

Best Practices for Classifying Node Groups

To organise node groups, begin with high-level functional groups which match the organisation's business requirements and work our way down to smaller segments inside those categories.

Environment vs Classification Node Groups

Nodes are assigned environments such as test, development, or production by environment node groups.

Each node group in the environment:

  • It must correlate to a Git branch in a control repo where targeted code deployments are desired. The name of the Git branch and the name of the environment group must be the same.
  • Must be a node group child of All Environments. Furthermore, except for one-time run exception subgroups used for canary testing, the environment node groups cannot have any child groups.
  • Classes or configuration data are not permitted.

Classification node groups give classification data, such as classes, parameters, and variables, to nodes. A node can be classified in more than one way.

  • Each classification node group must be a descendant of All Nodes or a different classification group.
  • In the group metadata, it must not get defined as an environment group.

Create Node Groups

Create node groups in the console to designate an environment or classification.

We have three actions to take to accomplish this:

1. In the console, navigate to Node groups and then Add group.

2. Configure the new node group's parameters.

3. Select Add.

As previously said, we can conduct the following:

Make environment node groups: Make our own environment node groups to target Puppet code deployments.

Make classification node groups: Nodes are assigned classification data via classification node groups. 

Add nodes to Node Group

A node can get added to a node group in two ways.

Statically add nodes to a node group

Individual nodes can get pinned to node groups. Individual node pinning is only advised if the node group contains only a few nodes. If we need to add certain specific nodes that did not get captured by the dynamic rules of the group, nodes can get pinned.

Dynamically add nodes to a node group

If we need to add a large number of nodes to a group, Dynamically adding nodes to a node group using logical rules that automatically add and remove nodes from the node groups is more useful.

Writing Node Group Rules

We must give a Fact, Operator, and Value when creating a dynamic node group rule. These three components are necessary for adding nodes to a node group dynamically.

The Fact column specifies the fact that the rule should use. We can select known facts from a dropdown list, enter part of a string to filter the list, or utilise structured or trustworthy facts.

The Operator field expresses the connection between the fact and the Value. It specifies how the rule makes use of the fact.

The Fact value is described in the Value field. The Value can be a string, numeric, or regular expression, depending on the Operator and Fact.

Using Structured and Trusted Facts for Node Group Rules

Structured facts are linked facts that are grouped together, and trustworthy facts are a sort of structured fact.

Structured facts are hashes or arrays of connected facts.

Trusted facts are a form of structured fact that is immutable and taken from the certificate of a node.

Declare Classes

Classes are Puppet code blocks that configure nodes and assign resources to them.

Enable Data Editing in the Console

By default, new Puppet Enterprise (PE) installations allow us to edit configuration data in the console.

Define Data Used by Node Groups

The console provides several methods for specifying data used in the manifests.

  • Set configuration data
  • Set parameters
  • Set variables

Set configuration data

In the same manner that Hiera data is used for automatic parameter search, configuration data set in the PE console is used. Although console configuration data takes precedence over Hiera data, data from both sources can be combined to configure nodes.

Set parameters

Parameters are stated resource-style, which implies they can be used to override other data. But, this override feature can produce class clashes and declaration errors, resulting in Puppet runs failing.

Set variables

Variables set in the console become top-scope variables, which are accessible to all Puppet manifests.

Variable-style syntax: The Value of the fact is interpolated using variable-style syntax.

Expression-style syntax: When we need to index into a fact, use expression-style syntax.

View Nodes in a Node Group

All nodes that currently match the rules provided for a node group can be viewed.

  1. Click Node groups in the console, and then we select the node group we want to see.
  2. We click on Matching nodes.

Making changes to node groups

We can change or delete node groups, remove nodes or classes from node groups, and change or remove parameters and variables.

Edit or Remove Node Groups

We can edit a node group to change its name, description, environment, environment group setting and even parent node group. Node groups with no children can be removed or deleted.

1. In the console, navigate to Node groups and choose a node group.

2. Commit changes.

Remove Nodes from a Node Group

To remove nodes from a node group, either unpin the node or delete (or update) the dynamic rule which added the node.

1. In the console, go to the Rules tab and choose the node group from which we wish to remove nodes.

2. To remove nodes introduced to a group by dynamic node group rules, first discover which rules are adding the nodes and then remove a single rule by clicking Remove. If no other rules match, this removes any additional nodes that match this rule.

3. In the Certname table, remove pinned nodes as follows:

a.To unpin a specific node, click Unpin.

b.To unpin all pinned nodes from the node group, click Unpin all pinned nodes. It does not remove nodes that were dynamically inserted.

4. Commit changes.

Environment Based Testing

The environment-based testing procedure enables us to test new code before it gets deployed to production.

Setting up environment-based testing necessitates the use of a certain node group hierarchy. Before we begin setting up environment-based testing, ensure that we know the difference between environment and categorisation node groups and how to create node groups.

The following is the fundamental node group hierarchy for environment-based testing:

1. Every Node

2. Every Environment

a. Node group for the production environment

b. Stating the environment node group

3. Test environment node group

a. One-time run exception node group in the test environment

4. Development environment

a. One-time run exception node group in the development environment

b. Group of PE Infrastructure nodes

c. Groups of classification nodes and their offspring

Test and Promote a Parameter

To test and promote a parameter, use an environment-based testing procedure.

  1. Make a classification node group. 
  2. Set a parameter to test in the new test group.
  3. If the test results are satisfactory, manually adjust the class parameter in the parent group to apply the modification to the production environment.
  4. Remove the child group that was utilised for testing.

Test and Promote a Class

To test and promote a class, use an environment-based testing workflow.

1. Make a node group for classification. Set the Environment node group to the test environment and the Parent node group to the appropriate production environment classification node group.

2. Declare a class to be tested in the new test group.

3. If the test results are satisfactory, apply the modification to the production environment by promoting the code having the new classes to production and declaring the class in the parent node group.

4. Remove the child group that was utilised for testing.

Test Code with Canary Nodes and Alternate Puppet Environments

We can run a one-time Puppet agent on specified canary nodes to test new code.

Create a one-time run exception child group under each environment node group where we want to test code to enable the canary workflow. When we run Puppet with the supplied environment, this group matches nodes on the fly. 

Preconfigured Node Groups

Puppet Enterprise comes with preset node groups for managing the setup.

All Nodes Node Group

This one is at the top of the hierarchical tree. This node group is the parent of all other node groups.

  1. Classes: There are no default classes. We recommend that the classes should not get added to this node group.
  2. Matching nodes: Every node.
  3. Notes: The preconfigured rule, which matches all nodes, cannot be changed or modified. 

Infrastructure Node Groups

PE gets managed through infrastructure node groups.

  • PE Infrastructure node group: The PE Infrastructure node group is the parent of all infrastructure node groups. This node group provides information such as service hostnames, service ports, and database information (excluding passwords).
  • PE Certificate Authority node group: This node group manages the certificate authority.
  • PE Master node group: The PE Master node group manages the primary server.
  • PE Compiler node group: This node group is a subclass of the PE Master node group and is used to manage compilers that run the PuppetDB service.
  • PE Orchestrator node group: This node group serves to control the PE orchestration services configuration, which covers things like task concurrency limitations, PCP broker timeout, and the number of JRubies that can operate in the orchestrator at the same time.
  • PE PuppetDB node group: This node group is used to administer the PuppetDB service nodes. If the node also functions as a compiler, it is classed as a member of the PE Compiler node group.
  • PE Console node group: This node group is used to handle the console.
  • PE Agent node group: This node group is used to handle agent configuration.
  • PE Infrastructure Agent node group: This node group is a subset of the PE Agent node group and is used to manage infrastructure-specific overrides.
  • PE Database node group: The PostgreSQL service is managed by the PE Database node group.

PE Patch Management Node Group

It is a parent node group for patch management nodes. Make child node groupings based on the requirements.

Environment Node Groups

Environment node groups are solely used to configure environments. They are unable to include any classification.

The preconfigured environment node groups vary depending on the version of PE we are using, and we can customise them as needed for the ecosystem. When we update from an earlier version of PE, the environment node groups remain the same as they were in the previous version.

Managing Windows Nodes

Puppet Enterprise can be used to manage the Windows setups, such as creating local group and user accounts,  controlling services, and executing basic administrative chores with Forge modules.

Manage Windows Services

Puppet can be used to manage Windows services by starting, stopping, enabling, disabling, listing, querying, and configuring them. We can ensure that particular services are always functioning or are disabled as needed in this manner.

To manage services in the manifest, we create Puppet code. The modifications we make to the service are applied when we apply the manifest.

We can do the following in response to this:

  • Check that a Windows service is running.
  • Disable a Windows service
  • Use Windows Task Scheduler to schedule a recurring operation.

Manage Windows Users and Groups

Puppet may be used to create user and group accounts locally. Local user accounts are frequently desired for isolating apps that require specific rights.

In relation to these assignments, things that can be done are:

  • Administrator accounts can get managed.
  • Set up an app to utilise a separate account.
  • Local groupings can get managed.

Using Windows Modules

Modules from the Forge can be used to conduct basic administrative activities on Windows nodes, such as controlling access control lists and registry keys, as well as installing and generating our own packages. We can accomplish the following with them:

The ACL module is used to manage permissions.

  • We can manage permission with the ACL module.
  • We can see the file permissions using ACL.
  • The chocolaty module lets us install, create, and repackage packages. 

Check out this problem - Connect Nodes At Same Level

Frequently Asked Questions

How is Puppet different from Ansible?

Unlike Ansible, Puppet employs a client-server architecture, and the Puppet agent must be installed on any servers managed by Puppet.

What exactly is a Puppet production environment?

A Puppet environment is a method of providing a specialised configuration to a small number of agent nodes. Each environment has its own Puppet configuration tree and can be thought of as a separate Puppet master server.

On a puppet agent, where are environments specified?

All configurations for the environment are done in the "puppet. conf" file. To indicate the environment the Puppet client should use, a value for the environment configuration variable in the client's "puppet. conf" file can be used.

Conclusion

We read about the advanced concepts of managing nodes in Puppet today. To understand it better, we went through grouping classifying to managing windows nodes. We also read about environment and classification node groups and saw different methods to add node groups. Refer to our courses and explore Coding Ninjas Studio to find more exciting stuff. You can also look into the interview experiences and solve different problems. Look into our Guided paths, test series, libraries and resources to know more.

Thank You

Happy Coding!

Live masterclass