【4】puppet笔记 - 数组、类
数组:http://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#arrays类:http://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html
数组:
[]:内用,分隔开,就组成一个数组,如:$a = ,$a = 1
$arr = ['one',"two","three"]
notice $arr
如下,执行代码后,会在file目录下面创建f1、f2文件,并把权限改成777
$files = ["/puppet/file/f1","/puppet/file/f2"]
file {
$files:
ensure => present,
mode => 777,
}
类:
class 类名 {
puppet代码,一般多个资源放在一起,比如安装软件、配置文件、运行状态
}
include 类名 ;执行类
注:类的命名很多类似:class base ,>class ntp { file {
"/etc/ntp.conf":
mode => 644,
owner => root,
group => hxw,
}
}
class ntp::run {
service {
"ntpd":
ensure => running,
}
}
include ntp,ntp::run
# puppet apply 5.pp
Notice: Scope(Class): one
Notice: Compiled catalog for pclient.onepc.com in environment production in 0.17 seconds
Notice: /Stage/Ntp/File/group: group changed 'root' to 'hxw'
Notice: /Stage/Ntp::Run/Service/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 0.23 seconds
类继承:
class ntp { file {
"/etc/ntp.conf":
mode => 644,
owner => root,
group => root,
}
}
class ntp::autorun inherits ntp {
service {
"ntpd":
ensure => running,
enable => true,
}
}
include ntp::autorun
# puppet apply 5.pp
Notice: Scope(Class): one
Notice: Compiled catalog for pclient.onepc.com in environment production in 0.16 seconds
Notice: /Stage/Ntp/File/group: group changed 'hxw' to 'root'
Notice: /Stage/Ntp::Autorun/Service/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 0.65 seconds
# chkconfig | grep ntpd
ntpd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
class ntp::autorun inherits ntp
使用 inherits继承类
页:
[1]