Monday 3 July 2017

Puppet

Puppet-1
Puppet is a Configuration Management tool that is used for deploying, configuring and managing servers. There are a couple of different tools that PuppetLabs provides (PuppetDB, Puppet Enterprise, Facter, Hiera), as well as models for using Puppet (client/server, where a server is referred to as a master, and clients check in to gather any updates to configuration and apply them to themselves; also master-less). Finally, there is a robust community of open-source tools around Puppet, such as r10k, and a number of community built modules that can be found on the Puppet Forge.


It performs the following functions: 
Defining distinct configurations for each and every host, and continuously checking and confirming whether the required configuration is in place and is not altered (if altered Puppet will revert back to the required configuration) on the host. 
Dynamic scaling-up and scaling-down of machines. 
Providing control over all your configured machines, so a centralized (master-server or repo-based) change gets propagated to all, automatically.



From the ground up, Puppet is organized as follows:

- Manifests, which contain Puppet code (a Ruby DSL), describing the desired configuration, contents, or execution for files, services, scripts, and other pieces of infrastructure 
- Modules, which group common manifests together to achieve some goal (e.g. an elasticsearch module could be used to install, configure, and start elasticsearch on a node) 
- Nodes, which are the systems to be configured by one or more modules 
- Environments, which are user-defined logical groupings, typically representing different versions of the total body of Puppet code, and typically aligned along SDLC states, like 'qa' or 'production'
At runtime, the Puppet executable applies (runs) the given modules for a particular matching node in the desired environment and prints its progress to stdout; if all goes well, at the end, your node should be configured as your Puppet code describes. 
Puppet code is composed primarily of resource declarations. A resource describes something about the state of the system, such as a certain user or file should exist, or a package should be installed. 
Here is an example of a user resource declaration:


user { 'mitchell':
  ensure     => present,
  uid        => '1000',
  gid        => '1000',
  shell      => '/bin/bash',
  home       => '/home/mitchell'
}
resource_type { 'resource_name'
  attribute => value
  ...
}
Therefore, the previous resource declaration describes a user resource named 'mitchell', with the specified attributes.
To list all of the default resource types that are available to Puppet, enter the following command:
puppet resource --types
We will cover a few more resource types throughout this tutorial.

Manifests

Puppet programs are called manifests. Manifests are composed of puppet code and their filenames use the .pp extension. The default main manifest in Puppet installed via apt is /etc/puppet/manifests/site.pp.
If you have followed the prerequisite Puppet tutorial, you have already written a manifest that creates a file and installs Apache. We will also write a few more in this tutorial.

Classes

In Puppet, classes are code blocks that can be called in a code elsewhere. Using classes allows you reuse Puppet code, and can make reading manifests easier.

Class Definition

A class definition is where the code that composes a class lives. Defining a class makes the class available to be used in manifests, but does not actually evaluate anything.
Here is how a class definition is formatted:
class example_class {
  ...
  code
  ...
}
The above defines a class named "example_class", and the Puppet code would go between the curly braces.

Class Declaration

A class declaration occurs when a class is called in a manifest. A class declaration tells Puppet to evaluate the code within the class. Class declarations come in two different flavors: normal and resource-like.
normal class declaration occurs when the include keyword is used in Puppet code, like so:
include example_class
This will cause Puppet to evaluate the code in example_class.
resource-like class declaration occurs when a class is declared like a resource, like so:
class { 'example_class': }
Using resource-like class declarations allows you to specify class parameters, which override the default values of class attributes. If you followed the prerequisite tutorial, you have already used a resource-like class declaration ("apache" class) when you used the PuppetLabs Apache module to install Apache on host2:
node 'host2' {
  class { 'apache': }             # use apache module
  apache::vhost { 'example.com':  # define vhost resource
    port    => '80',
    docroot => '/var/www/html'
  }
}
Now that you know about resources, manifests, and classes, you will want to learn about modules.

Modules

A module is a collection of manifests and data (such as facts, files, and templates), and they have a specific directory structure. Modules are useful for organizing your Puppet code, because they allow you to split your code into multiple manifests. It is considered best practice to use modules to organize almost all of your Puppet manifests.
To add a module to Puppet, place it in the /etc/puppet/modules directory.


If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you

Thanks
Devops Desk Team

No comments:

Post a Comment