A concrete example to simply illustrate the specific structure of puppet create the first configuration
A list of puppet that mainly contains these parts
resources, files, templates, nodes, classes, definitions
Puppet in the definition of a module, this is more important, is basically the core of puppet, the module is mainly composed of resources, files, templates, classes, definitions.
Puppet's manifest file ends with. PP, and does not need to be written when loading the file. pp extension.
Now let's create the first module:
First create Module
1 go to this directory2cd/etc/puppet/modules/3 mkdir MOTD #创建模块4 to view the directory tree of a module, you need to create it yourself5[Email protected] modules]# tree motd/6motd/7 ├──files #存放文件目录8 │└──etc9 │└──MOTD #文件Ten ├──manifests #存放模块pp配置文件目录 One │└──init.pp A └──templates #存放模板目录 - - 4Directories,2Files
Above is the directory of several basic modules, INIT.PP is the core configuration file of the module
Second, let's write the init.pp file.
1 [email protected] manifests]# cat init.pp2 classmotd{#定义一个类3package{'Setup':#定义package资源包4ensure =present, #要求setup这个包处于安装状态5 }6file{'/ETC/MOTD':#定义file资源7ensure =present, #要求文件存在8Owner ='Root',#要求file属主为root9Group ='Root',#要求file属组为rootTenmode ='0644', OneSource ="PUPPET:///MODULES/MOTD/ETC/MOTD",#文件在服务器上的位置 Arequire = package['Setup'], #要求文件在被配置之前执行package资源 - } -}
The following is a brief description:
Require is a meta-parameter that ensures that the package resource executes before the file is configured,
Under the instructions source, tell puppet where to look for this file, note that the path is "PUPPET:///MODULES/MOTD/ETC/MOTD" instead of this PUPPET:///MODULES/MOTD//FILES/ETC/MOTD
"Be sure to note that there is no files.
For the sake of observation we add something to the MOTD file
12 ---------------------3 This is puppet testing4 -----------------------
Third, write the site.pp file.
Do you remember the location of the site.pp file? Over here
1 [email protected] puppet]# pwd 2 /etc/puppet3 [[email protected] puppet]# tree manifests/4 manifests/5 └──site.pp 6 7 0 1 file
1$puppetserver ='puppetmaster.com'2Node'agent1.puppetmaster.com'{3 include MOTD4 }5 #或者使用正则表达式来写6#node/^ (agent.*) \.puppetmaster\.com$/7Node/^agent\d+\.puppetmaster\.com$/{8 include MOTD #包含这个类9 }Ten #或者更加简洁的方式使用通配符 OneNode/*. puppetmaster\.com/{ A include MOTD - }
Application of the first configuration
Performed on the client:
1[Email protected] ~]# puppet Agent-T2Notice:ignoring--Listen on onetime run3 info:retrieving pluginfacts4 info:retrieving Plugin5info:caching Catalog forAgent1.pup.yxnu6Info:applying Configuration version'1483969520'7Notice:/stage[main]/motd/file[/etc/motd]/content:8---/ETC/MOTD .- on- A +: -:22.000000000+08009+ +/tmp/puppet-file20170109-2933-1q3m9uz-0 .- on- the +: $:21.074912907+0800Ten@@ -0,0+1,3 @@ One+--------------------- A+ This isPuppet Testing -+----------------------- - theInfo:computing Checksum on file/etc/MOTD -Info:/STAGE[MAIN]/MOTD/FILE[/ETC/MOTD]: filebucketed/etc/MOTD to puppet with sum d41d8cd98f00b204e9800998ecf8427e -Notice:/stage[main]/motd/file[/etc/motd]/content:content changed'{md5}d41d8cd98f00b204e9800998ecf8427e'To'{md5}b97562be6190ed905ab4e86a21c4e0c9' -notice:finished Catalog Runinch 0.71seconds +[Email protected] ~]# cat/etc/Mo -modprobe.d/MOTD +[Email protected] ~]# cat/etc/MOTD A--------------------- at This isPuppet Testing ------------------------ -[Email protected] ~]#
View Code
Such a simple instance is done, and you can see that the file/ETC/MOTD is created on the client,
Quite simply, the next step is to introduce puppet basics and describe how to build more complex configurations
Puppet a complete example