puppet parser validate fails

143 views
Skip to first unread message

Andreas Dvorak

unread,
Dec 10, 2013, 9:31:07 AM12/10/13
to puppet...@googlegroups.com
Dear all,

In git I have a pre-receive script to checkt the puppet files. My git push comes with an error but if I run the same manually I get no error.
Can anybody please help me?

error message
remote:  Checking manifests/nodes.pp for syntax errors and styleguide compliance...
remote: 'puppet parser validate' failed on manifests/nodes.pp - push deniend. Run tests locally and confirm they pass before pushing.
remote: Error: Could not parse for environment production: No file(s) found for import of 'fix.pp' at /tmp/tmp.hujjYZKPpC/manifests/nodes.pp:9
remote: Error: Try 'puppet help parser validate' for usage

pre-receive script
for puppetmodule in `git diff-tree --no-commit-id --name-only -r $newrev`; do
        echo -e "\e[0;36m" "Checking $puppetmodule for syntax errors and styleguide compliance..." "\e[0m"
        tmpdir=`mktemp -d`
        tmpmodule="$tmpdir/$puppetmodule"
        tmperror="$tmpdir/errors.txt"
        mkdir -p $tmpmodule
        rmdir $tmpmodule
        git show $newrev:$puppetmodule > $tmpmodule
        case $puppetmodule in
                *.pp )
                puppet parser validate $tmpmodule 2&> $tmperror
                rc=$?
                if [[ $rc != 0 ]]; then
                                        echo -e "\e[0;31m'puppet parser validate' failed on $puppetmodule - push deniend. Run tests locally and confirm they pass before pushing. \e[0m"
                    cat $tmperror
                    rm -rf $tmpdir
                    exit $rc
                fi
 .....

this works without error in my local git and on the central git
puppet parser validate nodes.pp

cat nodes.pp
node base {
  include profiles::base
}

node 'sv2629.muc.baag' inherits base {
}

import 'fix.pp'
import 'puppet_master.pp'
#import 'sunray.pp'

And it does not matter what I change in the file.

Best regards
Andreas

Jeff Bachtel

unread,
Dec 10, 2013, 11:37:34 AM12/10/13
to puppet...@googlegroups.com
When git feeds the file to puppet parser on your git repo server, it is doing so via a temporary file (evidenced by remote: Error: Could not parse for environment production: No file(s) found for import of 'fix.pp' at /tmp/tmp.hujjYZKPpC/manifests/nodes.pp:9 ). Because it is a temporary file it does not have the rest of the git tree available, and so the import 'fix.pp'  line cannot succeed (on your git repo server. Obviously the file works perfectly fine with a working tree to use).


# NOTE: There is an outstanding bug against `puppet parser` which causes # the --ignoreimport option to turn the syntax check into a no-op. Until # the bug is resolved, the syntax check hook should not include the # --ignoreimport option and will only work correctly on manifests which # do not contain "import" lines. # See http://projects.puppetlabs.com/issues/9670

You can try to work around this on your server-side hook by changing
git cat-file blob $new_sha1 > $tmp

to

git cat-file blob $new_sha1 | grep -v '^\s*import' > $tmp

disclaimer - I've not tested this, I am not a doctor, etc.

Jeff



--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/e2d78e37-0746-4fed-b590-fd9246d4d605%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Andreas Dvorak

unread,
Dec 11, 2013, 3:20:02 AM12/11/13
to puppet...@googlegroups.com
Hi Jeff,

thank you for the information.

I think the "grep -v '^\s*import'" is working. First test are successfully.

Best regards
Andreas
Reply all
Reply to author
Forward
0 new messages