Puppet node节点的特性(十二)


前言:

    生产机器很多通常会新建nodes.pp文件和site.pp文件平级,存放于/etc/puppet/manifests/nodes.pp文件,这种方法比较常用.当然也有其他办法直接写入site.pp文件.

    nodes.pp文件主机匹配,支持正则表达式和继承.

    //:正则匹配

    "":精确匹配

    inherits:继承


实例:

先正则匹配然后在精确匹配.

node /sh-(proxy|web)\d+/ {
  case $::hostname {
    "sh-proxy2": {
         include apache
         user {"test1":
            ensure => present,
            }
      }
     "sh-web1": {
        include nginx::nginxconf
         } 
    }
}


比如sh-proxy不止sh-proxy2一台,有50台也可以匹配操作:

node /sh-(proxy|web)\d+/ {
  case $::hostname {
    /sh-proxy\d+/: {        #正则匹配
         include apache
         user {"test1":
            ensure => present,
            }
      }
     "sh-web1": {
            include nginx::nginxconf
         } 
    }
}


测试agent端更新:

[root@sh-proxy2 puppet]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-proxy2.localdomain
Info: Applying configuration version '1505706252'
Notice: /Stage[main]/Apache/Package[httpd]/ensure: created
Notice: Finished catalog run in 8.69 seconds

node节点继承(inherits)


1、新建一个admin模块,做selinux替换关闭.

/modules/admin/manifests/init.pp文件内容:

class admin {
    exec {"selinux":
    command => "sed -i '/^SELINUX=/s/=.*/=disabled/g' /etc/sysconfig/selinux",
    path => ["/bin/","/sbin/","/usr/bin/","/usr/sbin/"],
    user => root,
    group => root,
    }
}

wKioL1nAw8WyAzPEAAFb6Nin5HU496.png

注意:尝试定义类名'base'报错,现象:svn无法提交,但却可以更新,update后获取到master主机ip地址目录等信息,不确实是否和系统内置变量冲突.


manifests/nodes.pp文件内容.
    node base {
        include admin
}
node /sh-(proxy|web)\d+/  inherits base {
  case $::hostname {
    /sh-proxy\d+/: {
         include apache
         user {"test1":
            ensure => present,
            }
      }
     "sh-web1": {
        include nginx::nginxconf
         } 
    }
}


wKioL1nAw_vCspdIAAHBv-9Z3Dk369.png

注意:node节点名不能和模块名冲突,尝试定义为node admin,提交无报错,但是agent端无更新无修改无提示,修改为base以后agent端内容更新.





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值