zoukankan      html  css  js  c++  java
  • puppet一个完整的实例

    一个具体实例来简单说明puppet的具体结构

    创建第一个配置

    puppet的组成清单这主要包含这几个部分

    资源,文件,模板,节点,类,定义

    puppet中有个模块的定义,这个比较重要,基本是puppet的核心,这个模块主要是由资源,文件,模板,类,定义来组成的。

    puppet的清单文件是以.pp来结尾的,在载入文件的时候就不需要写.pp的扩展名了。

    现在我们来创建第一个模块:

    第一创建模块

     1 进入到这个目录下
     2 cd /etc/puppet/modules/
     3 mkdir motd    #创建模块
     4 查看模块的目录树,需要自己创建
     5 [root@pup modules]# tree motd/
     6 motd/
     7 ├── files    #存放文件目录
     8 │   └── etc
     9 │       └── motd   #文件
    10 ├── manifests     #存放模块pp配置文件目录
    11 │   └── init.pp
    12 └── templates    #存放模板目录
    13 
    14 4 directories, 2 files

    上面就是几个基本模块的目录,init.pp是模块的核心配置文件

    第二下面我们来写init.pp文件

     1 [root@pup manifests]# cat  init.pp 
     2 class motd{              #定义一个类
     3     package{'setup':     #定义package资源包
     4      ensure => present,  #要求setup这个包处于安装状态
     5 }
     6     file{'/etc/motd':     #定义file资源
     7      ensure => present,   #要求文件存在
     8      owner => 'root',       #要求file属主为root
     9      group => 'root',         #要求file属组为root
    10      mode => '0644',
    11      source => "puppet:///modules/motd/etc/motd",   #文件在服务器上的位置
    12      require => Package['setup'],  #要求文件在被配置之前执行package资源
    13 }
    14 }

    简单说明下:

    require是个元参数,确保能够先执行,上面就是在文件在被配置之前执行package资源,

    在说明下source,告诉puppet去哪里寻找这个文件,注意路径是“puppet:///modules/motd/etc/motd“ 而不是这个puppet:///modules/motd//files/etc/motd

    ”一定要注意没有files。

    为了便于观察我们在motd文件中添加一点东西

    1 [root@pup etc]# cat motd 
    2 ---------------------
    3 this is puppet testing
    4 -----------------------

     第三来编写site.pp文件

    还记得site.pp文件的位置吗?在这里

    1 [root@pup puppet]# pwd
    2 /etc/puppet
    3 [root@pup puppet]# tree manifests/
    4 manifests/
    5 └── site.pp
    6 
    7 0 directories, 1 file
     1 $puppetserver = 'puppetmaster.com'
     2 node 'agent1.puppetmaster.com'{
     3     include motd
     4 }
     5 #或者使用正则表达式来写
     6 #node /^(agent.*).puppetmaster.com$/
     7 node /^agentd+.puppetmaster.com$/{
     8     include motd     #包含这个类
     9 }
    10 #或者更加简洁的方式使用通配符
    11 node /*.puppetmaster.com/{
    12        include motd
    13 }

    第四应用第一个配置

    客户端上执行:

     1 [root@agent1 ~]# puppet agent -t
     2 Notice: Ignoring --listen on onetime run
     3 Info: Retrieving pluginfacts
     4 Info: Retrieving plugin
     5 Info: Caching catalog for agent1.pup.yxnu
     6 Info: Applying configuration version '1483969520'
     7 Notice: /Stage[main]/Motd/File[/etc/motd]/content: 
     8 --- /etc/motd    2010-01-12 21:28:22.000000000 +0800
     9 +++ /tmp/puppet-file20170109-2933-1q3m9uz-0    2017-01-09 21:45:21.074912907 +0800
    10 @@ -0,0 +1,3 @@
    11 +---------------------
    12 +this is puppet testing
    13 +-----------------------
    14 
    15 Info: Computing checksum on file /etc/motd
    16 Info: /Stage[main]/Motd/File[/etc/motd]: Filebucketed /etc/motd to puppet with sum d41d8cd98f00b204e9800998ecf8427e
    17 Notice: /Stage[main]/Motd/File[/etc/motd]/content: content changed '{md5}d41d8cd98f00b204e9800998ecf8427e' to '{md5}b97562be6190ed905ab4e86a21c4e0c9'
    18 Notice: Finished catalog run in 0.71 seconds
    19 [root@agent1 ~]# cat /etc/mo
    20 modprobe.d/ motd        
    21 [root@agent1 ~]# cat /etc/motd 
    22 ---------------------
    23 this is puppet testing
    24 -----------------------
    25 [root@agent1 ~]# 
    View Code

    这样一个简单的实例就完成了,可以看到在客户端上会创建文件/etc/motd,

    很简单吧,接下来会介绍puppet基础知识,并且介绍如何构建更加复杂的配置

  • 相关阅读:
    弹窗拖拽组件开发应用
    高级事件的运用
    常见排序算法(JS版)
    原生js实现仿window10系统日历效果
    原生js实现吸顶导航和回到顶部特效
    OVN实战---《The OVN Gateway Router》翻译
    OVN实战---《An Introduction to OVN Routing》翻译
    OVN实战---《A Primer on OVN》翻译
    深入理解CNI
    《CNI specification》翻译
  • 原文地址:https://www.cnblogs.com/Dicky-Zhang/p/6266608.html
Copyright © 2011-2022 走看看