使用include> 2、类的继承:
class B_name inherits A_name
3、子类的命名方式:
父类::子类
示例:
修改node.pp文件,增加sh-web1主机匹配.
注释:sh-web1声明nginx类.
node /sh-(proxy|web)\d+/ {
case $::hostname {
"sh-proxy2": {
include apache
user {"test1":
ensure => present,
}
}
"sh-web1": {
include nginx
}
}
}
puppet代码nginx>modules/nginx/manifests/init.pp文件(无参数的类定义).
class nginx {
package {"nginx":
ensure=> present,
}
}
puppet代码apche>modules/apache/manifests/init.pp文件(有参数的类定义).
class apache ($sta = "present") {
package {"httpd":
ensure=> $sta,
}
}
sh-web1更新agent安装nginx报错如下:
[root@sh-web1 puppet]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1505454999'
Error: Execution of '/usr/bin/yum -d 0 -e 0 -y list nginx' returned 1: Error: No matching Packages to list
Error: /Stage[main]/Nginx/Package[nginx]/ensure: change from absent to present failed: Execution of '/usr/bin/yum -d 0 -e 0 -y list nginx' returned 1: Error: No matching Packages to list
Notice: Finished catalog run in 6.93 seconds
原因:没有release源,更新安装eple-release源即可.
# yum install epel-release -y 更新安装nginx.
[root@sh-web1 puppet]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version '1505454999'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Notice: Finished catalog run in 34.99 seconds
Class类的继承(inherits)
注意:子类的命名不支持特殊符号'.',支持下划线'_'
示例:
新建:modules\nginx\manifests\nginx.conf.pp
class nginx::nginxconf inherits nginx {
file {"/etc/nginx/nginx.conf":