Begin

In a text editor — vimemacs, or nano — create a file with the following contents and filename: written and applied your first Puppet manifest.

[root@yum01 ~]# useradd testuser
[root@yum01 ~]# cat /etc/passwd |grep test
testuser:x:536:536::/home/testuser:/bin/bash
[root@yum01 ~]# pwd
/root
[root@yum01 ~]# vim user-absent.pp
[root@yum01 ~]# cat user-absent.pp
user {'testuser':
ensure => absent,
}
[root@yum01 ~]# puppet apply /root/user-absent.pp
Notice: Compiled catalog for yum01.test.com in environment production in 7.99 seconds
Notice: /Stage[main]/Main/User[testuser]/ensure: removed
Notice: Finished catalog run in 4.34 seconds
[root@yum01 ~]# puppet apply /root/user-absent.pp
Notice: Compiled catalog for yum01.test.com in environment production in 0.27 seconds
Notice: Finished catalog run in 0.03 seconds
[root@yum01 ~]# cat /etc/passwd |grep test

Manifests

Puppet programs are called “manifests,” and they use the .pp file extension.

The core of the Puppet language is the resource declaration. A resource declaration describes a desired state for one resource.

Puppet Apply

Like resource in the last chapter, apply is a Puppet subcommand. It takes the name of a manifest file as its argument, and enforces the desired state described in the manifest.

We’ll use it below to test small manifests, but it can be used for larger jobs too. In fact, it can do nearly everything an agent/master Puppet environment can do.

Resource Declarations

Let’s start by looking at a single resource:

[root@yum01 ~]# ls -l /tmp/ |grep test
[root@yum01 ~]# vim file-1.pp
[root@yum01 ~]# cat file-1.pp
file {'testfile':
path => '/tmp/testfile',
ensure => present,
mode => 0640,
content => "i am a test file",
}

  • The type (file, in this case)
  • An opening curly brace ({)
    • The title (testfile)
    • A colon (:)
    • A set of attribute => value pairs, with a comma after each pair (path => '/tmp/testfile', etc.)
  • A closing curly brace (})

[root@yum01 ~]# pwd
/root
[root@yum01 ~]# puppet apply /root/file-1.pp
Notice: Compiled catalog for yum01.test.com in environment production in 0.18 seconds
Notice: /Stage[main]/Main/File[testfile]/ensure: created
Notice: Finished catalog run in 0.32 seconds
[root@yum01 ~]# ls -l /tmp/ |grep test
-rw-r----- 1 root root 16 Nov 6 06:50 testfile
[root@yum01 ~]# cat /tmp/testfile
i am a test file

Puppet noticed that the file didn’t exist, and created it. It set the desired content and mode at the same time.

If we try changing the mode and applying the manifest again, Puppet will fix it:

[root@yum01 ~]# chmod 666 /tmp/testfile
[root@yum01 ~]# ls -l /tmp/ |grep test
-rw-rw-rw- 1 root root 16 Nov 6 06:50 testfile
[root@yum01 ~]# puppet apply /root/file-1.pp
Notice: Compiled catalog for yum01.test.com in environment production in 0.22 seconds
Notice: /Stage[main]/Main/File[testfile]/mode: mode changed '0666' to '0640'
Notice: Finished catalog run in 0.27 seconds
[root@yum01 ~]# ls -l /tmp/ |grep test
-rw-r----- 1 root root 16 Nov 6 06:50 testfile

Once More, With Feeling!

Now that you know resource declarations, let’s play with the file type some more. We’ll:

  • Put multiple resources of different types in the same manifest
  • Use new values for the ensure attribute
  • Find an attribute with a special relationship to the resource title
  • See what happens when we leave off certain attributes
  • See some automatic permission adjustments on directories

[root@yum01 ~]# vim file-2.pp
[root@yum01 ~]# cat file-2.pp
file {'/tmp/test1':
ensure => file,
content => "hi.\n",
}

file {'/tmp/test2':
ensure => directory,
mode => 0644,
}

file {'/tmp/test3':
ensure => link,
target => '/tmp/test1',
}

notify {" iam nofitying you":}
notify {"so am i" :}

[root@yum01 ~]# puppet apply /root/file-2.pp
Notice: Compiled catalog for yum01.test.com in environment production in 0.18 seconds
Notice: /Stage[main]/Main/File[/tmp/test1]/ensure: defined content as '{md5}4e9141e3aa25c784aa6bc0b2892c12d9'
Notice: /Stage[main]/Main/File[/tmp/test3]/ensure: created
Notice: /Stage[main]/Main/File[/tmp/test2]/ensure: created
Notice: iam nofitying you
Notice: /Stage[main]/Main/Notify[ iam nofitying you]/message: defined 'message' as ' iam nofitying you'
Notice: so am i
Notice: /Stage[main]/Main/Notify[so am i]/message: defined 'message' as 'so am i'
Notice: Finished catalog run in 0.14 seconds

New Ensure Values, Different States

The ensure attribute is somewhat special. It’s available on most (but not all) resource types, and it controls whether the resource exists, with the definition of “exists” being somewhat local.

With files, there are several ways to exist:

  • As a normal file (ensure => file)
  • As a directory (ensure => directory)
  • As a symlink (ensure => link)
  • As any of the above (ensure => present)
  • As nothing (ensure => absent).

Titles and Namevars

Notice how our original file resource had a path attribute, but our next three left it out?

Almost every resource type has one attribute whose value defaults to the resource’s title. For the file resource, that’s path. Most of the time (usergrouppackage…), it’sname.

The Site Manifest and Puppet Agen

We’ve seen how to use puppet apply to directly apply manifests on one system. The puppet master/agent services work very similarly, but with a few key differences:

Puppet apply:

  • A user executes a command, triggering a Puppet run.
  • Puppet apply reads the manifest passed to it, compiles it into a catalog, and applies the catalog.

Puppet agent/master:

  • Puppet agent runs as a service, and triggers a Puppet run about every half hour (configurable).
  • Puppet agent does not have access to any manifests; instead, it requests a pre-compiled catalog from a puppet master server.
  • The puppet master always reads one special manifest, called the “site manifest” or site.pp. It uses this to compile a catalog, which it sends back to the agent. ----site.pp
  • After getting the catalog, the agent applies it.

This way, you can have many machines being configured by Puppet, while only maintaining your manifests on one (or a few) servers. This also gives some extra security, as described above under “Compilation.”

Exercise: Use Puppet Agent/Master to Apply the Same Configuration

To see how the same manifest code works in puppet agent:

[root@centos manifests]# pwd
/etc/puppet/manifests
[root@centos manifests]# vim file.pp
[root@centos manifests]# cat file.pp
file {'/tmp/test11111111':
ensure => file,
content => "hi. this is a test 111111 file \n",
}
[root@centos manifests]# vim site.pp
[root@centos manifests]# cat site.pp
import 'file.pp'

[root@yum01 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for yum01.test.com
Info: Applying configuration version '1415262208'
Notice: /Stage[main]/Main/File[/tmp/test11111111]/ensure: defined content as '{md5}cb94281a2c8ccc1c3a64aa2c0e04721e'
Notice: Finished catalog run in 0.14 seconds
[root@yum01 ~]# cat /tmp/test11111111
hi. this is a test 111111 file

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

转载于:https://www.cnblogs.com/oskb/p/4078968.html

Learning Puppet — Manifests相关推荐

  1. windows puppet manifests 文件维护

    初级 puppet windows agent实现简单的msi格式安装包安装及bat文件创建; 对windows推送时上一级目录不存在报此错误 fileserver.conf 推送source 目录配 ...

  2. Puppet扩展篇1-自定义fact结合ENC(hirea)的应用实践

    零基础学习Puppet自动化配置管理系列文档 在大量节点加入Puppet之后,你至少会面临两个比较大的问题: 1.由于节点数的增多,site.pp文件必然会编写更多的节点条目,以及节点包含的类.假设你 ...

  3. puppet yum模块、配置仓储、mount模块

    转载:http://blog.51cto.com/ywzhou/1577335 作用:自动为客户端配置YUM源,为使用yum安装软件包提供便捷. 1.服务端配置yum模块 (1)模块清单 [root@ ...

  4. puppet(1.7-2.1)

    puppet配置模块(一) 模块是puppet的最大单元,模块里面有类,类下面有资源.同步文件.远程执行命令.cron等叫做资源,都是通过模块来实现的.下面我们来定义一个模块: 在服务端上做如下操作: ...

  5. puppet中master和agent之间实现通信

    puppet master和agent实现通信 1 安装puppet 1)master端 192.168.196.183     master.example.com agent端     192.1 ...

  6. puppet自动化运维之资源关系

    2019独角兽企业重金招聘Python工程师标准>>> 1.引用资源 当我们引用一个资源时,需要大写资源类型的首字母,例如File[sshdconfig].当看到一个大写的资源类型, ...

  7. puppet 连载二:服务端和客户端安装(ActiveMQ、MCollective)

    -------------------------------------服务端----------------------------------- 1.jdk安装 vi /etc/profile ...

  8. puppet 深入讲解

    一.Modules概述 到目前为止,关于puppet的资源申报.定义类.声明类等所有功能都只能在一个manifest(清单)文件中实现,但这却非最有效的基于puppet管理IT基础架构的方式 实践中, ...

  9. 客户端安装服务器的路径查找文件,柴少鹏的官方网站-puppet系列(一)之puppet的部署、配置文件以及命令详解...

    一.puppet的介绍(文字解释部分参考了权威指南) 作为自动化运维管理老大哥级别的软件,这个词大家都很熟悉了,我也就不阐述什么发展史啊,跟其他工具的对比了.不过有一点是要注意的,puppet分为社区 ...

最新文章

  1. ecshop 解密index.php,ECShop 2.x 3.0代码执行漏洞分析
  2. TCP/IP——基本知识
  3. 文巾解题 477. 汉明距离总和
  4. Linux 之三 静态库及动态库的编写和使用
  5. 未捕获typeerror: $形象。cropper不是函数_没有学不会的python--细说函数
  6. 在linux上面找一个脚本,30个Linux Shell脚本经典案例
  7. html js 读取资源文件,使用HTML5和JQuery读取CSV(Text)文件的实例
  8. c语言中x的n次方怎么表示_为什么一定要慎用C语言标准库中的pow函数,你知道吗?...
  9. windows scrip host报错代码:800A00D
  10. 金融分析(三)------联合分布,边缘分布,条件概率密度
  11. 研究生如何写好毕业论文?(上)【中国人民大学龚新奇】
  12. 《谷歌大数据经典论文读后感》
  13. 一些情况及问题的说明
  14. 谷粒学院day08——课程章节与小节的实现
  15. C++在终端、文件中就地覆盖输出的方法
  16. 电力行业三次谐波计算
  17. Kendo ui 使用总结----Kendo UI 模板
  18. [结构光三维重建] 2、基于结构光的三维重建系统工作原理总结
  19. 【JavaSE专栏2】JDK、JRE和JVM
  20. 电子商务系统的运维与评价(十三)

热门文章

  1. java怎么连发子弹_HTML-坦克大战-完成子弹连发功能(三)
  2. 极简浏览器主页网址导航自定义网址壁纸云端同步简洁清爽
  3. 想进入IT行业,自学还是选择培训机构。
  4. 【开源】这个人脸生成器厉害了,网红脸、明星脸、萌娃脸通通都有
  5. three.js 实现波纹效果
  6. C/C++编程学习:百行代码实现小游戏(剪刀石头布)
  7. Ubuntu 16.04 查看软件包的命令技巧
  8. 微服务架构的简单实现-Stardust
  9. 分享两篇适合程序员看的书籍——《谁动了我的奶酪》、《你的灯亮着吗?》读后感
  10. matlab的汉明窗函数如何导出,基于汉明窗函数的FIR低通滤波器的设计.doc