Updating Puppet Manifests to Conform to New Standards

Puppet recently published some new standards to apply to manifests which will require single quotes around switch statement keys and around file object modes. The exception to this rule would be if the key were a variable as then it would be enclose by double quotes.

All of this is covered in the recently release style guide.

I upgraded a puppet client to 3.7.4 using the ruby gem on AWS and had to update all manifests that had a switch statement or file object with a mode attribute to get past warnings. This is how I updated the file modes:

# update all file objects to enclose modes in single quotes - note that this is OSX compatible sed, as well as gnu
cd puppet_repo
for file in $(egrep -iR 'mode.*=> \d\d\d,' * | awk '{print $1}' | uniq)
  echo "file: ${file}"
  sed 's#mode.*=>.*\([0-9]\{3,4\}\)#mode => '"'"'\1'"'"'#g' ${file} > ${file}.new
  mv ${file}.new ${file}

This will then allow you to commit changes to git and deploy to your puppet master or nodes. Note that this only works if there is a single space between the => and the mode.






Leave a Reply

Your email address will not be published. Required fields are marked *