puppet parser命令主要用于对*.pp文件语法检测,检查文件语法是否正确需要加validate动作参数.
语法正确,没有任何返回.
[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后面的冒号去掉)
[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文件.)
[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 validatepuppet parser validate ./2.pp Error: Could not parse for environment production: Syntax error at 'ensure'; expected '}' at /root/2.pp:2puppet 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