|
数组:http://docs.puppetlabs.com/puppet/latest/reference/lang_datatypes.html#arrays
类:http://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html
数组:
[]:内用,分隔开,就组成一个数组,如:$a = [1,"one",'two'] ,$a[0] = 1
$arr = ['one',"two","three"]
notice $arr[0]
如下,执行代码后,会在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
[root@pclient test]# puppet apply 5.pp
Notice: Scope(Class[main]): one
Notice: Compiled catalog for pclient.onepc.com in environment production in 0.17 seconds
Notice: /Stage[main]/Ntp/File[/etc/ntp.conf]/group: group changed 'root' to 'hxw'
Notice: /Stage[main]/Ntp::Run/Service[ntpd]/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
[root@pclient test]# puppet apply 5.pp
Notice: Scope(Class[main]): one
Notice: Compiled catalog for pclient.onepc.com in environment production in 0.16 seconds
Notice: /Stage[main]/Ntp/File[/etc/ntp.conf]/group: group changed 'hxw' to 'root'
Notice: /Stage[main]/Ntp::Autorun/Service[ntpd]/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 0.65 seconds
[root@pclient test]# chkconfig | grep ntpd
ntpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
class ntp::autorun inherits ntp
使用 inherits继承类 |
|
|