本文档提供了Puppet语言的基本语法参考,帮助您了解如何编写有效的Puppet配置。
变量
Puppet中的变量用于存储数据,变量名通常以 $
符号开头。
$var_name
- 示例:
$server_ip = '192.168.1.1'
模板
Puppet使用模板来生成配置文件,模板通常使用ERB(嵌入式Ruby)语法。
{{ var_name }}
- 示例:
{{ $server_ip }}
条件语句
Puppet支持常见的条件语句,如if/else。
if $os_type == 'Linux' {
notify { 'Linux OS Detected':
message => 'Detected Linux OS',
}
} else {
notify { 'Non-Linux OS Detected':
message => 'Detected Non-Linux OS',
}
}
循环
Puppet支持循环语句,如for。
for $i in ['a', 'b', 'c'] {
notify { "Letter $i":
message => "This is letter $i",
}
}
资源
资源是Puppet中最基本的配置单元,用于描述系统应该如何配置。
service { 'httpd': ensure => 'running', enable => true, }
链接
更多关于Puppet语法的详细内容,请参阅官方文档。
Puppet Logo