puppet自动化运维之tag标签puppet自动化运维之tag标签

简介:

   标签能更好的让puppet识别一段代码。同时,客户端也可以执行指定的tag,而不需要全部都执行。

 

tag元参数,用于标签资源;

tag函数,用于标签容器;

tagged函数,用于判断一个容器,是否有某个标签,即用于检查tag函数。

 

puppet的自动分配标签分两种:资源和容器。默认是以自己的类型,作为标签名。

 

资源自动分配标签的特点:

       ①自己的资源类型;

       title

       ③所在容器的类型;

       ④所在容器的tital和每个命名空间;

       ⑤继承的tag

 

容器自动分配标签的特点:

       ①自己的类型;

       title和每个命名空间;

       ③所在容器的类型;

       ④所在容器的tital和每个命名空间;

       ⑤继承的tag

 

注:凡title的内容有“/”,该title不会被添加为标签名。

 

#title/

file {"/tmp/filebucket":

       ensure   => file,

       content   => "hello wrold",

}

 

#title不含/

file {"filebucket":

       ensure   => file,

       content   => "hello wrold",

       path   => "/tmp/filebucke ",

}

 

 

 

①.tag元参数:

 

       一般用于,各种资源,可以使用数组。

格式:

 

       tag => "标签名",

       tag => ["标签名1",…, "标签名n"],

 

注:可放入到任何一类资源。

 

例:

#

cron { "run-puppet":

          command => "/usr/sbin/puppet agent --server=master.perofu.com   --test >/dev/null    2>&1",

          minute => inline_template("<%= (hostname+name).hash.abs % 60   %>"),

          tag => "cron_test",

}

 

#

[root@master manifests]# crontab -l

# HEADER: This file was autogenerated at   Fri Mar 21 15:24:59 +0800 2014 by puppet.

# HEADER: While it can still be managed   manually, it is definitely not recommended.

# HEADER: Note particularly that the   comments starting with 'Puppet Name' should

# HEADER: not be deleted, as doing so   could cause duplicate cron jobs.

 

[root@master ~]# puppet agent   --server=master.perofu.com --test --tags cron_test

info: Caching catalog for master.perofu.com

info: Applying configuration version   '1395386333'

notice:   /Stage[main]//Cron[run-puppet]/ensure: created

notice: Finished catalog run in 0.04   seconds

[root@master manifests]# crontab -l

# HEADER: This file was autogenerated at   Fri Mar 21 15:43:55 +0800 2014 by puppet.

# HEADER: While it can still be managed   manually, it is definitely not recommended.

# HEADER: Note particularly that the   comments starting with 'Puppet Name' should

# HEADER: not be deleted, as doing so   could cause duplicate cron jobs.

# Puppet Name:   run-puppet

32 * * * *   /usr/sbin/puppet agent --server=master.perofu.com --test >/dev/null  2>&1

 

 

 

②.tag函数:

       tag函数可以为容器添加标签,,默认就是标签名,个人理解:容器差不多是类,因为类用的多。

 

       如果用户想添加另外的tag,需要class第一行,进行定义。

 

格式:

 

       class   类名{

              tag("标签名")

              …….

}

 

 

例:

#容器的标签名现在有两个:sshsecurity

class ssh{

       tag("security")

       service{"sshd":

              ensure => running,

              enable => true,

       }

}


 

③.tagged函数:

 

    判断一个容器的标签,即tag函数,是否被定义过。

 

vi site.pp

if tagged("sss"){

    $a="The tag is sss"

} else {

    $a="The tag is NONE"

}


file {"/tmp/temp.txt"

    content => "$a",

}

#

cat /tmp/temp.txt

The tag is NONE

 

 

④.如何查看生成的tag标签:

    可查看/var/lib/puppet/reports/节点/yaml







     本文转自yzy121403725 51CTO博客,原文链接:http://blog.51cto.com/lookingdream/1852916 ,如需转载请自行联系原作者


相关文章
|
4月前
|
人工智能 运维 监控
运维安全还能靠“人盯人”?别闹了,聊聊自动化处理的真功夫
运维安全还能靠“人盯人”?别闹了,聊聊自动化处理的真功夫
199 17
|
9月前
|
数据采集 机器学习/深度学习 人工智能
运维人的“福音”?AI 驱动的自动化网络监控到底香不香!
运维人的“福音”?AI 驱动的自动化网络监控到底香不香!
1069 0
|
6月前
|
人工智能 运维 安全
运维老哥的救星?AI 驱动的自动化配置管理新趋势
运维老哥的救星?AI 驱动的自动化配置管理新趋势
342 11
|
8月前
|
机器学习/深度学习 人工智能 运维
运维不背锅,从“自动修锅”开始:AI自动化运维是怎么回事?
运维不背锅,从“自动修锅”开始:AI自动化运维是怎么回事?
468 49
|
7月前
|
运维 Prometheus 监控
系统崩了怪运维?别闹了,你该问问有没有自动化!
系统崩了怪运维?别闹了,你该问问有没有自动化!
213 9
|
7月前
|
运维 监控 应用服务中间件
运维打铁: Ruby 脚本在运维自动化中的应用探索
Ruby 是一种简洁、动态类型的编程语言,适合运维自动化任务。本文介绍了其在服务器配置管理、定时任务执行和日志分析处理中的应用,并提供了代码示例,展示了 Ruby 在运维自动化中的实际价值。
229 2
|
7月前
|
机器学习/深度学习 运维 监控
智能运维Agent:自动化运维的新范式
在数字化转型浪潮中,智能运维Agent正重塑运维模式。它融合人工智能与自动化技术,实现从被动响应到主动预防的转变。本文详解其四大核心功能:系统监控、故障诊断、容量规划与安全响应,探讨如何构建高效、可靠的自动化运维体系,助力企业实现7×24小时无人值守运维,推动运维效率与智能化水平全面提升。
1696 0
|
7月前
|
运维 监控 安全
从实践到自动化:现代运维管理的转型与挑战
本文探讨了现代运维管理从传统人工模式向自动化转型的必要性与路径,分析了传统运维的痛点,如效率低、响应慢、依赖经验等问题,并介绍了自动化运维在提升效率、降低成本、增强系统稳定性与安全性方面的优势。结合技术工具与实践案例,文章展示了企业如何通过自动化实现运维升级,推动数字化转型,提升业务竞争力。
|
8月前
|
人工智能 缓存 运维
运维人不用秃头了?AI自动化配置管理了解一下!
运维人不用秃头了?AI自动化配置管理了解一下!
187 0
|
11月前
|
机器学习/深度学习 人工智能 运维
机器学习+自动化运维:让服务器自己修Bug,运维变轻松!
机器学习+自动化运维:让服务器自己修Bug,运维变轻松!
456 14

热门文章

最新文章

推荐镜像

更多