What is Puppet Domain-Specific Language?
Last Updated :
04 Jan, 2023
Puppet is an open-source configuration management automation tool. Puppet permits system administrators to type in infrastructure as code, using the Puppet Descriptive Language rather than utilizing any customized and individual scripts to do so. This means in case the system administrator erroneously alters the state of the machine, at that point puppet can uphold the change and guarantee that the framework returns to the required state. A conventional approach would require the system administrator to login to each machine to perform framework organization assignments but that does not scale well.
Puppet Architecture
Puppet uses the client/server model. The server is called a puppet master. The puppet master stores the recipes or manifests( code containing resources and desired states) for clients. The clients are called Puppet nodes and runs the puppet agent software. The node runs a puppet daemon(agent) to connect to the puppet master. These nodes will download the manifest assigned to the node from the puppet master and apply the configuration if needed.
How does puppet works?
A puppet run starts with the nodes and not the master. This run uses SSL services to pass data packets back and forth between the nodes and master. The nodes run the factor command to assemble information about the system. These facts are then sent to master.
Once the master receives the facts, it compiles a catalog that describes the state of each resource in the node. The master compares the host-name of each node and matches it to the specific node configuration or uses the default configuration if the node does not match. After the catalog is compiled, the puppet master sends it to the node. Puppet will apply the catalog on the node, ensuring the system is in the desired state.
Puppet Blocks
- Resources- Puppet has many built-in resources like file, user, package and service. The puppet language allows administrators to manage the system resources independently and ensure that the system is in the desired state. The example of the resources are package, service, notify, user, exec, and many more. The puppet resource_type command lists the available resource types on a Puppet host. The syntax for a resource_type is as follows:
resource_type { 'resource_title':
attr1 => value1,
attr2 => value2,
attr3 => value3,
...
attrN => valueN,
}
The resource deceleration starts with declaring the type of the resource. Puppet has many built-in resource types like file, user, package, and service. The resource type is followed by curly brackets (braces) that include the resource title and the list of value/attribute pairs. The resource title is a string enclosed within single quotes. A colon separator is used to separate the resource tile and the list of attribute/value pairs.
Each resource has its attributes that are also called as parameters. For example, the file has attributes like path, owner, group, ensure, and mode. These attributes are defined as a value using => operator. For example, the owner can have a value of root or the user account that has created the file. As well as, the mode of the file can be 750 or 777 depending on what kind of permission is needed for the file.
Resource Title
The resource title should be defined with utmost care. The title informs the Puppet Compiler about the resource to be actioned on. Multiple similar "resource titles" may have the same attributes. In that case, they can be grouped together in a single resource definition. A similar example is shown below
file { [ '/etc/firewalld',
'/etc/firewalld/helpers',
'/etc/firewalld/services',
'/etc/firewalld/ipsets' ]:
ensure => 'directory',
owner => 'root',
group => 'root',
mode => '750',
}
- The following example shows the declaration for the firewalld service.
service { 'httpd':
ensure => 'running',
enable => true,
}
Puppet-Resource Type- Puppet Manifests– Puppet Manifests are the text documents written in Puppet DSL that describes the end state of the host system. It can be creates using any text editor and the extension of it .pp extension. The following noalice.pp will ensure that Puppet deletes an account called alice from the system.
[root@master ~]# vim alice.pp
[root@master ~]# cat noalice.pp
user {'alice':
ensure => 'absent',
}
- Puppet Classes- Puppet Classes helps to ensure that the Puppet resource definitions can be made more robust and reusable so that they can be applied to multiple hosts. A puppet class is usually used to define all the resources that are needed to implement a service or run an application. The following example demonstrates the syntax of the class
class class_name ($param = 'value') {
resource definitions...
}
The following example demonstrates a class called test
class test {
user { 'master':
ensure => 'present',
home => '/home/master',
shell => '/bin/bash',
}
file { '/home/master':
ensure => 'directory',
owner => 'master',
group => 'master',
mode => '0770',
require => User['master'],
}
package { 'httpd':
ensure => 'present',
}
service { 'httpd':
ensure => 'running',
enable => true,
require => Package['httpd'],
}
}
include test # include is a function that is used to call the class test in the manifest
- The include command is used in a manifest to use a class. It is similar to calling a previously defined function in a programming language
- Puppet Modules- Puppet module is a way of packaging puppet manifests and related files into a single file. The module is a tar archive that has an established hierarchy. Puppet module provides a standard, predictable directory structure for the puppet code and related files that they contain. Some of the essential or most frequently used directories in a module hierarchy are listed below:
- Manifests directory contains all of the puppet manifests defined in the module.
- File directory contains static files
- lib/factor directory contains custom fact definitions
- The test directory contains manifests that are used to test the functionality provided by the module.
- Evaluating the templates
- Performing mathematical calculations
- Modifies the catalog
- Catalog Statements like include, require, contain and tag
- Logging statements like debug, info, notice, warning, err.
- Failure statements like fail.
- The function_name is the full name of the function.
- An opening parentheses to include the list of the arguments. (Parentheses are not required while using the statement functions like include <class-name>). In all the other cases its needed. To understand what are the arguments required by a function, it can be checked in the documentation of that function. In case of an opening parentheses there should be a closing one.
- Code block or lambda in case the function needs one.
Similar Reads
What is High Level Language?
Computer languages have a huge importance in the digital world. If you want to create anything such as an application, website, software, or game you need to write it using a coding language, which is most probably a high-level language because they are easier to use and understand by humans. In thi
7 min read
What is Machine Language?
Machine language is a low-level programming language that is understood by computers. Machine language is made up of binary bits 0 and 1. Machine language is also known as machine codes or object code. As machine language consists of only 0 and 1, that's why it is difficult to understand in raw form
4 min read
What is Fourth Generation Programming Language?
The language which is used to create programs is called a programming language. It comprises a set of instructions that are used to produce various kinds of output. A Fourth Generation Programming Language (4GL) is designed to make coding easier and faster for people by using more human-friendly com
4 min read
Android - Per App Language Preference with Example
Many android applications add localization within their application to provide multi-lingual support within their android application. While implementing this feature the android application will take the device language to set the language for the android application and we cannot change the langua
6 min read
How to Implement Per-App Language Preference in Android 13?
Multilingual users frequently set their system language to one language, like English, but they want to choose different languages for particular programs, like Malayalam, Chinese, or Hindi. Android 13 offers the following improvements for apps that support several languages in order to better serve
4 min read
Language Processing Activities
Language processing activity bridges the ideas of software designers with actual execution on the computer system. The designer expresses the idea related to the application domain of the software. To implement these ideas, the description of the ideas has to be interpreted as related to the executi
3 min read
Introduction to Scripting Languages
All scripting languages are programming languages. The scripting language is basically a language where instructions are written for a run time environment. They do not require the compilation step and are rather interpreted. It brings new functions to applications and glue complex system together.
3 min read
Which Programming Language to Choose?
One of the most annoying question today is which programming language should be chosen for the sake of education/career or anything. Answer for this question to many programmers ends up with C or C++, or mostly Java but why C? why C++? Why Java?. Today many software exists, to solve a problem but al
4 min read
How to Detect Browser Language in PHP?
We can detect requesting browser's language using PHP's super global variable $_SERVER. It is a superglobal variable that holds information about headers, paths, and script locations. It is basically an associative array in PHP which has keys like SERVER_NAME, SERVER_ADDR, REQUEST_METHOD, etc. We ca
1 min read
Interpreter Design Pattern
The Interpreter Design Pattern is a behavioral design pattern used to define a language's grammar and provide an interpreter to process statements in that language. It is useful for parsing and executing expressions or commands in a system. By breaking down complex problems into smaller, understanda
10 min read