Table of contents
1.
Introduction
2.
What are Modules in Bolt?
3.
Dependency Management 
4.
Module Path
5.
Compatibility with Bolt Versions
5.1.
Install puppet enterprise
5.2.
Migrating a Project
6.
Installing Modules 
7.
Create a Project
8.
Install A Module To An Existing Project
9.
Install Associated Modules with Your Bolt Project
10.
Forcible Installation 
11.
Manual Module Specification
12.
Pin a Module Version
13.
Install Modules Using Proxy 
14.
Install Using Tokens of Authorization.
15.
Frequently Asked Questions
15.1.
What do you mean by modulepath?
15.2.
What is the use of Modules in Bolt?
15.3.
What does puppetlabs/ruby_task_helper do?
15.4.
What is the extension for plans in Bolt?
15.5.
What are some local modules available in bolt?
16.
Conclusion
Last Updated: Oct 28, 2024

Basics of Modules in Bolt

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

Introduction

This blog will help to understand the basic concepts of modules in Bolt. Bolt is an orchestration tool to automate the configuration of devices. You can install Bolt on any operating system and automate the servers and applications.

Inrroduction

Bolt can deploy applications, debug servers, patch and upgrade systems, or halt and restart services. This blog will guide you about modules in bolt, module dependency, and different ways to install these modules. 

What are Modules in Bolt?

In general, modules are a part of a program containing one or more components and can be added and removed from the system easily. The modules in Bolt are directories containing puppet codes. Modules include plans and tasks that help in managing applications. You can install these modules in Bolt and use them in your workflows. 

You can also create your own plans and tasks in Bolt and use them later via these modules in your program. Modules are dependent on one another for proper working. Let's discuss the dependency management of modules in Bolt. 

Dependency Management 

When you install a module in Bolt, it automatically adds all the modules on which it depends. These modules and their dependencies will be added under the module key section of the configuration file (bolt-project.yaml file). Go to the folder where Bolt is installed to view this configuration file. You will see the following files, out of which one is the 'bolt-project.yaml' file.

project files

By default, the configuration files look like this:

configuration files

For example: If we create a project with the name 'bolt-codingninjas' and add mysql and apache modules, then the configuration file will be:

configuration files after addition

Bolt installs all the dependencies like translate, stdlib, concat, etc, and the corresponding puppet file for the project will contain:

# Puppetfile
...
moduledir '.modules'
mod 'puppetlabs/apache', '5.6.0'
mod 'puppetlabs/puppetserver_gem', '1.1.1'
mod 'puppetlabs/resource_api', '1.1.0'
mod 'puppetlabs/translate', '2.2.0'
mod 'puppetlabs/stdlib', '6.5.0'
mod 'puppetlabs/mysql', '10.8.0'
mod 'puppetlabs/concat', '6.2.0'

Module Path

There is a list of directories where Bolt search for content. It is called the modulepath. Bolt obtains content from-

  • The current project.
  • Any modules that are present in the configurable modules directory. By default, that directory is modules/.
  • The module directories that are managed by Bolt (.modules).
  • Any modules that come with Bolt.

The modulepath directory accepts multiple directories like an array. When you want to add, remove or modify any directory from Bolt's module path, then you can add, remove, or change the path of that directory in your 'bolt-project.yaml' file.

The command used to list all the directories and modules loading from the current module path is:

bolt module show (*nix shell)
Get-BoltModule (in power shell)

Compatibility with Bolt Versions

Module dependency management was introduced in Bolt 2.23.0 version. And switching to this version, you may find past projects that no longer work as expected. The changes introduced are:

Install puppet enterprise

As the modules in Bolt are automatically added to the Puppet file, you have to install puppet enterprise if you are using this feature. 

Migrating a Project

It becomes easy to migrate a file using the module dependency feature. You can use the 'migrate' command that provides the following features:

  1. Upgrade projects to use module dependency management features. 
  2. Upgrade projects to use the 'bolt-project.yaml' configuration file instead of the 'bolt.yaml' file. 
  3. Update inventory files. 
     

The command used to migrate the projects using the 'migrate' command of the module dependency feature is:

bolt project migrate

Installing Modules 

We can use the command line to implement the following tasks.

  • Create a project using pre-installed modules. 
  • Add a Puppet Forge module. 
  • Install modules associated with the bolt project. 
  • Update project modules.

Create a Project

You can create a new project either by using pre-installed modules or installing new modules and dependencies using the bolt command line. Bolt installs the latest versions of all the modules and their dependencies. 

For instance, if we want to turn the current directory into a project named 'exampleCodingNinjas_project' which has puppetlabs/mysql modules installed, the command used will be:

In Nix shell 
bolt project init examplecodingninjas_project --modules puppetlabs-mysql

In Power Shell 
New-BoltProject -Name examplecodingninjas_project -Modules puppetlabs-mysql

Install A Module To An Existing Project

To install a new module to an existing project, ensure that the project is configured with dependency management, i.e., the module key must be present in the 'bolt-project.yaml' file. If not, then migrate your project. You can add a forge module and dependencies to a current project using the command:

In Nix Shell 
bolt module add <module_name>

In Power Shell
Add-BoltModule -Module <module_name>

Bolt will add these modules and keep all the pre-installed modules in the same version until a conflict occurs. It might be updated to a newer version in case of any conflict. 

Install Associated Modules with Your Bolt Project

The following code comes in handy while installing the modules associated with a bolt project.

In Nix shell 
bolt module install

In Power Shell 
Install-BoltModule

Forcible Installation 

Avoid or be careful while manually modifying your configuration file or puppet file. Because while installing the modules, bolt compares the module specification in both these files to check if the puppet file is managed by bolt. If found some missing specifications, then the bolt raises an error containing:

Puppetfile at /<project_name>/Puppetfile does not include modules that

satisfy the following specifications:

- name: puppetlabs-ruby-task-helper

This might not be a Puppetfile managed by Bolt. 

 

In this case, you can forcible overwrite the module specification using the 

following code:

In Nix shell 
bolt module install --force Copied!

In Power Shell
Install-BoltModule -Force

Manual Module Specification

Sometimes you need to specify a module in the project configuration file manually. In this case, you can list the module specification under the module key. The key specifications of a forge module include:

  • Full name of the module
  • Version requirement (optional)
  • Resolve factor of whether to resolve the module's dependencies (optional)

For example: To install the apache module of version 5.0.0/5.x along with resolving the specification, will be like this:

modules:
  - name: puppetlabs/apache
     version_requirement: '5.x'
     resolve: true

The key specifications of git modules are a bit different from forge modules. These include:

  • Git repository URL. 
  • Name of the module (optional)
  • resolve factor (optional)
  • Git reference that be either a branch, commit, or tag. 
     

For example: To add the apache module having reference 1.0.0, the specification is:

modules: 
   - name: apache
      git: git@github.com:puppetlabs/apache
      ref: 1.0.0 
      resolve: false

The resolve key is set to false if you want to skip the dependency resolution for a module. 

Must Read Apache Server

Pin a Module Version

To give a specific version to a module in your bolt project, you can perform the following steps:

  • Search for the module in your configuration file.
  • Add the version you want to specify in the version-requirement key.
  • Run the install command along with the 'force' option to ensure that no version conflict occurs. 

Install Modules Using Proxy 

For declaring a global proxy that can be used to install Forge and git modules set the proxy key under module-install to the following:

# bolt-coding-ninjas-project.yaml
module-install:
  proxy: https://proxy.com:8080

It is also possible to set a proxy that is only used when installing Forge modules. To do the same, set the proxy key under the forge section of the module-install option:

# bolt-coding-ninjas-project.yaml
module-install:
  forge:
    proxy: https://forge-proxy.com:8080

Install Using Tokens of Authorization.

If you intend to set an authorization token for installing Forge modules, set the authorization_token key under the forge section of the module-install option. When you set the authorization_token key, you must also take care of the baseurl key.

# bolt-coding-ninjas-project.yaml
module-install:
  forge:
    authorization_token: <your-autorization-token>
    baseurl: https://forge.example.com

For information on how to install modules in bolts, you can refer to the official documentation.

Check out most important Git Interview Questions here.

Frequently Asked Questions

What do you mean by modulepath?

There is a list of directories where Bolt search for content. It is called the modulepath.

What is the use of Modules in Bolt?

Modules solve use cases and manage applications. Modules include helpful plans and tasks. They also allow to share of custom bolt tasks or utilize the bolt content programmatically.

What does puppetlabs/ruby_task_helper do?

The puppetlabs/ruby_task_helper serves as a helper for writing tasks in ruby.

What is the extension for plans in Bolt?

Plans must end in the .pp or .yaml extensions.

What are some local modules available in bolt?

Aggregate, Canary, puppert_connect, and puppetdb are some local modules. 

Conclusion

This blog discussed the concept of modules in the bolt. It also discussed the task of dependency management.

For more information on Bolt, you can refer to the following articles-

 

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses and refer to the mock test and problems available. Take a look at the interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass