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:
[root@centos ~]# 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 many subcommands.resource: Theresourcesubcommand can inspect and modify resources interactively.service: The first argument to thepuppet resourcecommand 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:
[root@centos ~]# 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 attributepuppet describe <TYPE>— Print long information, similar to what appears in thetype reference.
[root@centos ~]# 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
[root@centos ~]# 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:
[root@centos ~]# 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
Learning Puppet — Resources and the RAL的更多相关文章
- Learning Puppet — Resource Ordering
Learning Puppet — Resource Ordering Learn about dependencies and refresh events, manage the relation ...
- Learning Puppet — Manifests
Begin In a text editor — vim, emacs, or nano — create a file with the following contents and filenam ...
- Learning Puppet — Variables, Conditionals, and Facts
Begin $my_variable = "A bunch of text" notify {$my_variable:} Yup, that’s a variable, all ...
- Learning Django Resources
Learning Django Django makes it easier to build better Web apps more quickly and with less code. Web ...
- [ Learning ] Spring Resources
1. Spring MVC Spring MVC原理及配置详解 springMVC系列之(三) spring+springMVC集成(annotation方式) Mybatis3+Spring4+Sp ...
- 【机器学习Machine Learning】资料大全
昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料
<Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost到随机森林.D ...
- 机器学习(Machine Learning)&深入学习(Deep Learning)资料
<Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost 到随机森林. ...
- 机器学习(Machine Learning)&深度学习(Deep Learning)资料【转】
转自:机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一 ...
随机推荐
- 快速掌握grep命令及正则表达式
Linux系统自带了支持拓展正则表达式的 GNU 版本 grep 工具,所有的Linux发行版中均默认安装grep ,grep 命令被用来检索一台服务器或工作站上任何位置的文本信息,如何在 Linux ...
- 彻底弄懂css中单位px和em,rem的区别 转的自己看
国内的设计师大都喜欢用px,而国外的网站大都喜欢用em和rem,那么三者有什么区别,又各自有什么优劣呢? PX特点 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的 ...
- 331. Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, ...
- 图像质量评价指标之Matlab实现
在图像处理算法研究中,很多时候需要有客观评价指标来对算法的性能进行评价. 比如,在图像复原.图像滤波算法研究中,需要采用客观评价指标来定量的来测试算法恢复出的图像相对于参考图像的好坏程度. 本文介绍文 ...
- makefile--统一目标输出目录 (六)
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ 上一节我们把规则单独提取出来,方便了Makefile的维护,每个模块只需要给出关于自己的一些变量 ...
- MySQL二进制日志的备份和恢复
二进制日志:记录数据库修改的相关操作,作用是即时点回复,主从复制 可以按时间滚动,也可以按大小滚动 server-id:服务器身份标识 一.二进制文件的删除方法,千万不要手动删除 PURGE BINA ...
- Codeforces Round #373 (Div. 1)
Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...
- hdu3072 强连通+最小树形图
题意:有一个人他要把一个消息通知到所有人,已知一些通知关系:A 能通知 B,需要花费 v,而又知道,如果某一个小团体,其中的成员相互都能直接或间接通知到,那么他们之间的消息传递是不需要花费的,现在问这 ...
- lucene文件格式待整理
这是之前Lucene3.0生成的索引格式 a表
- CorelDRAW中拆清除调和效果的技巧
图形对象应用的调和效果达不到用户的满意,可以将该种调和效果清除,清除调和效果后,只保留起始对象和结束对象.CorelDRAW软件支持两种方法来清除调和对象,本教程将详解CorelDRAW中清除调和效果 ...