puppet parser命令主要用于对*.pp文件语法检测,检查文件语法是否正确需要加validate动作参数.
语法正确,没有任何返回.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@puppet ~]
# cat 2.pp
user {
'root'
:
ensure =>
'present'
,
comment =>
'root'
,
gid =>
'0'
,
home =>
'/root'
,
password =>
'$6$yIyAnjPI1kiwQpe7$N0Lq9PrISqc5FRvWYbyS7tRSDE2lGLhdbQU/adpVAGbBpRsUSQ6GR22REoV9IJa9pPTHrKEOeShC2TZF3CUx3.'
,
password_max_age =>
'99999'
,
password_min_age =>
'0'
,
shell =>
'/bin/bash'
,
uid =>
'0'
,
}
[root@puppet ~]
# puppet parser validate 2.pp
|
把上段的puppet代码修改为错误的puppet代码测试:(root后面的冒号去掉)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@puppet ~]
# cat 2.pp
user {
'root'
ensure =>
'present'
,
comment =>
'root'
,
gid =>
'0'
,
home =>
'/root'
,
password =>
'$6$yIyAnjPI1kiwQpe7$N0Lq9PrISqc5FRvWYbyS7tRSDE2lGLhdbQU/adpVAGbBpRsUSQ6GR22REoV9IJa9pPTHrKEOeShC2TZF3CUx3.'
,
password_max_age =>
'99999'
,
password_min_age =>
'0'
,
shell =>
'/bin/bash'
,
uid =>
'0'
,
}
[root@puppet ~]
# puppet parser validate 2.pp
Error: Could not parse
for
environment production: Syntax error at
'ensure'
; expected
'}'
at
/root/2
.pp:2
|
批量检测多个*.pp文件:(puppet resource快速生成3个*.pp文件.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
[root@puppet ~]
# cat 2.pp
user {
'root'
ensure =>
'present'
,
comment =>
'root'
,
gid =>
'0'
,
home =>
'/root'
,
password =>
'$6$yIyAnjPI1kiwQpe7$N0Lq9PrISqc5FRvWYbyS7tRSDE2lGLhdbQU/adpVAGbBpRsUSQ6GR22REoV9IJa9pPTHrKEOeShC2TZF3CUx3.'
,
password_max_age =>
'99999'
,
password_min_age =>
'0'
,
shell =>
'/bin/bash'
,
uid =>
'0'
,
}
[root@puppet ~]
# cat 3.pp
package {
'httpd'
:
ensure =>
'absent'
,
}
[root@puppet ~]
# cat 4.pp
package {
'nginx'
:
ensure =>
'absent'
,
}
[root@puppet ~]
# find ./* -type f -name "*.pp" |xargs -n1 -t puppet parser validate
puppet parser validate .
/2
.pp
Error: Could not parse
for
environment production: Syntax error at
'ensure'
; expected
'}'
at
/root/2
.pp:2
puppet parser validate .
/3
.pp
puppet parser validate .
/4
.pp
puppet parser validate .
/example-meng/tests/init
.pp
puppet parser validate .
/example-meng/manifests/init
.pp
|
本文转自青衫解衣 51CTO博客,原文链接:http://blog.51cto.com/215687833/1964847