https://github.com/wikimedia/operations-puppet
Raw File
Tip revision: 06f74bc13e0ed8374978e56a8ae1ce8a37611557 authored by cpettet on 02 June 2014, 19:10:19 UTC
absent csalvia admin yaml
Tip revision: 06f74bc
linter
#!/bin/bash

usage ()
{
  echo "${0} -- linting puppet files"
  echo ''
  echo '        * Without argument it lints mod files in "git status"'
  echo '        * $1 can also be a path directive to find .pp files under'
  echo '        * $1 as "site" lints site.pp explicitly'
  echo ''
  exit
}

bold=`/usr/bin/tput -T xterm-256color setaf bold`
normal=`/usr/bin/tput -T xterm-256color setaf sgr0`

PUPPET_LINTER=/usr/bin/puppet-lint
test -x $PUPPET_LINTER || { echo "$PUPPET_LINTER not installed";
        if [ "$1" = "-h" ]; then exit 0;
        else usage; exit 1; fi; }

if [ "$1" == "-h" ]
  then
    usage
    exit 0
fi

if [ "$1" == "site" ]
  then
    pfiles="manifests/site.pp"
elif [ "$#" -gt 0 ]
  then
    pfiles=`find ${1}/* | grep .pp`
else
  pfiles=`git status | grep modified | awk '{print $3}'`
fi

if [ ${#pfiles[@]} -eq 0 ]; then
  echo "No files found to lint"
fi

linter () {
  tmp=`mktemp -u /tmp/%s.XXXX`
  for file in $1
    do
      puppet-lint $file > $tmp
      if [ -s $tmp ]
        then
          echo "${bold}${file}${normal}"
          grep --color -E '^|WARNING|ERROR' $tmp
          printf '%0.1s' "-"{1..60}; echo ""
      fi
    rm $tmp
  done
}

linter $pfiles
back to top