puppet自动化运维之tag标签puppet自动化运维之tag标签
2016-09-15 10:54
309 查看
标签能更好的让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_testinfo: Caching catalog for master.perofu.cominfo: Applying configuration version '1395386333'notice: /Stage[main]//Cron[run-puppet]/ensure: creatednotice: 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-puppet32 * * * * /usr/sbin/puppet agent --server=master.perofu.com --test >/dev/null 2>&1 |
②.tag函数:
tag函数可以为容器添加标签,类名,默认就是标签名,个人理解:容器差不多是类,因为类用的多。 如果用户想添加另外的tag,需要在class的第一行,进行定义。 格式:class 类名{ tag("标签名") …….} |
#容器的标签名现在有两个:ssh和securityclass ssh{ tag("security") service{"sshd": ensure => running, enable => true, }} |
③.tagged函数:
判断一个容器的标签,即tag函数,是否被定义过。vi site.ppif tagged("sss"){ $a="The tag is sss"} else { $a="The tag is NONE"} file {"/tmp/temp.txt" content => "$a",}#cat /tmp/temp.txtThe tag is NONE |
④.如何查看生成的tag标签:
可查看/var/lib/puppet/reports/节点/yaml相关文章推荐
- puppet自动化运维之tag标签
- 自动化运维工具Puppet学习 - 第一篇
- 自动化运维三贱客之 Puppet 安装
- linux运维自动化之puppet简单应用(一)
- puppet自动化运维之运算符及正则表达式
- 运维自动化之puppet类(4)
- puppet自动化运维之tidy资源
- puppet自动化运维之file资源优化
- 自动化运维之Puppet
- 运维自动化管理之puppet + nginx 部署与配置
- Puppet Saltstatck Ansible 自动化运维工具对比
- puppet、Ansible、SaltStack 自动化运维工具简单对比
- 自动化运维平台puppet的高级应用
- Puppet---自动化运维工具(进阶)
- 运维自动化之puppet模块(5)
- 自动化运维工具puppet一:puppet资源及单机模型
- puppet自动化运维之cron资源
- 自动化运维专题之puppet课程内容大纲
- 自动化运维---puppet入门