Learning Puppet — Resources and the RAL

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 run puppet 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 single puppetcommand, which has many subcommands.
  • resource: The resource subcommand can inspect and modify resources interactively.
  • service: The first argument to the puppet resource command must be a resource 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 many 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 would on Linux, and even across Linux distributions there’s some variety. But conceptually, you’re still starting or stopping a service, regardless of what you type into the console.

Abstraction

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 abstraction layer (RAL). The RAL consists of types (high-level models) and providers (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 of a resource type and is identified by atitle; it has a number of attributes (which are defined by the type), and each attribute has a value.

Puppet uses its own language to describe and manage resources:

[[email protected] ~]# puppet resource user
user { ‘HELLO‘:
ensure => ‘present‘,
gid => ‘503‘,
home => ‘/home/HELLO‘,
password => ‘!!‘,
password_max_age => ‘99999‘,
password_min_age => ‘0‘,
shell => ‘/bin/bash‘,
uid => ‘502‘,
}

This syntax is called a resource declaration. You saw it earlier when you ran puppet 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

The puppet describe subcommand can list info about the currently installed resource 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 the ...
computer - Computer object management using DirectorySer ...
cron - Installs and 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 - Installs and 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 (as
provided in the `gid` attribute), the user resource will autorequire
that group. If Puppet is managing any role accounts corresponding to the
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 called puppet 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 => ‘503‘,
home => ‘/home/HELLO‘,
password => ‘!!‘,
password_max_age => ‘99999‘,
password_min_age => ‘0‘,
shell => ‘/bin/bash‘,
uid => ‘502‘,
}

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

  

时间: 2024-07-30 19:43:58

Learning Puppet — Resources and the RAL的相关文章

Learning Puppet — Resource Ordering

Learning Puppet — Resource Ordering Learn about dependencies and refresh events, manage the relationships between resources, and discover the fundamental Puppet design pattern. Disorder Let’s look back on one of our manifests from the last page: [[em

Learning Puppet — Manifests

Begin In a text editor — vim, emacs, or nano — create a file with the following contents and filename: written and applied your first Puppet manifest. [[email protected] ~]# useradd testuser [[email protected] ~]# cat /etc/passwd |grep testtestuser:x

Learning Puppet — Variables, Conditionals, and Facts

Begin $my_variable = "A bunch of text" notify {$my_variable:} Yup, that’s a variable, all right. refer: https://docs.puppetlabs.com/learning/variables.html

puppet 安装及核心资源注解

-----本文大纲 简介 工作原理 puppet安装及命令解析 puppet资源类型 --------------------- 一.简介 puppet是一种Linux.Unix.windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件.用户.cron任务.软件包.系统服务等.puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系. puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互.每个客户端

puppet学习与精通之入门

puppet 入门 Skip to end of metadata 1puppet 是什么 puppet是一个开源的软件自动化配置和部署工具,很多大型IT公司均在使用puppet对集群中的软件进行管理和部署. 2.  设计架构 puppet是基于c/s架构的.服务器端保存着所有对客户端服务器的配置代码,在puppet里面叫做manifest. 客户端下载manifest之后,可以根据manifest对服务器进行配置,例如软件包管理,用户管理和文件管理等等. 如上图所示,puppet的工作流程如下

Decision Boundaries for Deep Learning and other Machine Learning classifiers

Decision Boundaries for Deep Learning and other Machine Learning classifiers H2O, one of the leading deep learning framework in python, is now available in R. We will show how to get started with H2O, its working, plotting of decision boundaries and

机器学习(Machine Learning)&amp;深度学习(Deep Learning)资料

机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost到随机森林.Deep Learning. <Deep Learning in Neural Networks: An Overview> 介绍:这是瑞士人工智能实验室Jurgen Schmidhuber写的最新版本

机器学习(Machine Learning)&amp;深入学习(Deep Learning)资料

<Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost 到随机森林.Deep Learning. <Deep Learning in Neural Networks: An Overview> 介绍:这是瑞士人工智能实验室 Jurgen Schmidhuber 写的最新版本<神经网络与深度学习综述>本综述的特点是以时间排序,从 1940 年开始讲起,到

puppet知识简记

Puppet 开始 安装 aptitude install puppet puppetmaster 工作机制 puppet是通过ssl方式进行安全通信的,在正常同步前,需要进行证书的获取和认证 puppet运行机制大概是这样: 客户端向服务端发送facts信息,请求返回catalog, 服务端检查类文件等的关于客户端的信息打包catalog返回给客户端, 客户端按照catalog进行一系列检查同步操作. puppet资源类型及属性 3.1 资源 资源是puppet处理主机而分解的基本元素,资源的