Learning Puppet-Resources and the RAL

Source: Internet
Author: User
Learning Puppet-Resources and the RAL

Welcome to Learning Puppet! This series covers the basics of writing Puppet code

Begin

Log into the Learning Puppet VM as root, and runPuppet resource service. This command will return something like the following:

[[Email protected] ~] # Puppet resource service | more
Service {'abrtd ':
Ensure => 'running ',
Enable => 'true ',
}
Service {'acpid ':
Ensure => 'running ',
Enable => 'true ',
}
Service {'atd ':
Ensure => 'running ',
Enable => 'true ',
}
Service {'auditd ':
Ensure => 'running ',
Enable => 'true ',
}
Service {'cgconfig ':
Ensure => 'stopped ',
Enable => 'false ',
}
Service {'cgred ':
Ensure => 'stopped ',
Enable => 'false ',

Okay! You 've just met your first Puppet resources.

What Just Happened?
  • Puppet: Most of Puppet's functionality comes from a singlePuppetCommand, which has subcommands.
  • Resource:ResourceSubcommand can inspect and modify resources interactively.
  • Service: The first argument toPuppet resourceCommand must beResource type,Which you'll learn more about below. A full list of types can be found at the Puppet type reference.

Taken together, this command inspected every service on the system, whether running or stopped.

Resources

Imagine a system's configuration as a collection of specified independent atomic units; call them"Resources ."

These pieces vary in size, complexity, and lifespan. Any of the following (and more) can be modeled as a single resource:

  • A user account
  • A specific file
  • A directory of files
  • A software package
  • A running service
  • A scheduled cron job
  • An invocation of a shell command, when certain conditions are met

Any single resource is very similar to a group of related resources:

  • Every file has a path and an owner
  • Every user has a name, a UID, and a group

The implementation might differ-for example, you 'd need a different command to start or stop a service on Windows than you wocould on Linux, and even guest SS Linux distributions there's some variety. but conceptually, you're still starting or stopping a service, regardless of what you type into the console.

Invalid action

If you think about resources in this way, there are two notable insights you can derive:

  • Similar resources can be grouped into types.Services will tend to look like services, and users will tend to look like users.
  • The description of a resource type can be separated from its implementation.You can talk about whether a service is started without needing to know how to start it.

To these, Puppet adds a third insight:

  • With a good enough description of a resource type,It's possible to declare a desired state for a resource-Instead of saying "run this command that starts a service," say "ensure this service is running ."

These three insights form Puppet's resource allocation action layer (RAL). The RAL consistsTypes(High-level models) andProviders(Platform-specific implementations)-by splitting the two, it lets you describe desired resource states in a way that isn't tied to a specific OS.

Anatomy of a Resource

In Puppet, every resource is an instance ofResource typeAnd is identified byTitle;It has a numberAttributes(Which are defined by the type), and each attribute hasValue.

Puppet uses its own language to describe and manage resources:

[[Email protected] ~] # Puppet resource user
User {'hello ':
Ensure => 'present ',
Gid => '20140901 ',
Home => '/home/hello ',
Password => '!! ',
Password_max_age => '123 ',
Password_min_age => '0 ',
Shell => '/bin/Bash ',
Uid => '000000 ',
}

This syntax is calledResource declaration.You saw it earlier when you ranPuppet resource service, And it's the heart of the Puppet language. It describes a desired state for a resource, without mentioning any steps that must be taken to reach that state.

Puppet Describe

ThePuppet describeSubcommand can list info aboutCurrently installedResource types on a given machine. This is different from the type reference because it also catches plugins installed by a user, in addition to the built-in types.

  • Puppet describe-l-List all of the resource types available on the system.
  • Puppet describe-s <TYPE>-Print short information about a type, without describing every attribute
  • Puppet describe <TYPE>-Print long information, similar to what appears in thetype reference.

[[Email protected] ~] # Puppet describe-l
These are the types known to puppet:
Augeas-Apply a change or an array of changes to...
Computer-Computer object management using DirectorySer...
Cron-installand manages cron jobs
Exec-Executes external commands
File-Manages files, including their content, owner...
Filebucket-A repository for storing and retrieving file...
Group-Manage groups
Host-installand manages host entries
Interface-This represents a router or switch interface
K5login-Manage the '. K5login' file for a user

[[Email protected] ~] # Puppet describe-s user

User
====
Manage users. This type is mostly built to manage system
Users, so it is lacking some features useful for managing normal
Users.
This resource type uses the prescribed native tools for creating
Groups and generally uses POSIX APIs for retrieving information
About them. It does not directly modify '/etc/passwd' or anything.
** Autorequires: ** If Puppet is managing the user's primary group (
Provided in the 'gid' attribute), the user resource will autorequire
That group. If Puppet is managing any role accounts corresponding to
User's roles, the user resource will autorequire those role accounts.


Parameters
----------
Allowdupe, attribute_membership, attributes, auth_membership, auths,
Comment, ensure, expiry, forcelocal, gid, groups, home, ia_load_module,
Iterations, key_membership, keys, managehome, membership, name,
Password, password_max_age, password_min_age, profile_membership,
Profiles, project, purge_ssh_keys, role_membership, roles, salt, shell,
System, uid

Providers
---------
Aix, directoryservice, hpuxuseradd, ldap, pw, user_role_add, useradd,
Windows_adsi

The Puppet Resource Command

Puppet includes a command calledPuppet resource, Which can interactively inspect and modify resources on a single system.

Usage of puppet resource is as follows:

[[Email protected] ~] # Puppet resource user HELLO
User {'hello ':
Ensure => 'present ',
Gid => '20140901 ',
Home => '/home/hello ',
Password => '!! ',
Password_max_age => '123 ',
Password_min_age => '0 ',
Shell => '/bin/Bash ',
Uid => '000000 ',
}

 

Refer: https://docs.puppetlabs.com/learning/ral.html

Learning Puppet-Resources and the RAL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.