Puppet Code Syntax Checks
Its time to move forward with the assurance of correct code syntax for the Puppet Code we have written, so far we have developed our expertise for below Puppet concepts:
Start Automation with Puppet
Puppet Enterprise Stack
Puppet Enterprise Master Installation
Puppet Agent Installation
Puppet Master-Agent Communication Model
Puppet Certification Management
Puppet Resources
Puppet Resources-II
We have written some of the basic Puppet Codes, but is it safe to run them directly without any assurance of its successful run or not?. There are few best practices which Puppetlabs suggests to follow before running the code into your infrastructure and Code Syntax Checking is one of them.
Lets see the two main paths where we usually keep our Puppet Code used for deployments, whenever you are doing any testing you can create a code under “/etc/puppetlabs/code/environments/production/manifests/*.pp” and actually the codes will be there in the modules for whole application stack at “/etc/puppetlabs/code/environments/production/modules/<module-name>/<module-structure>.
The same can be checked or changed by changing the appropriate attributes in puppet.conf file in Puppet Master (/etc/puppetlabs/puppet/puppet.conf).
Lets suppose we have created a Puppet Code for testing inside main /etc/puppetlabs/code/environments/production/manifests directory with name thinknyx.pp. But we need to check the Code Syntax before doing the smoke test (next level of code testing) and then final run. Below is the way to check the Puppet Code syntax:
Code Details:
cat /etc/puppetlabs/code/environments/production/manifests/thinknyx.pp user { ‘thinknyx’: ensure => ‘present’, uid => ‘700’ gid => ‘700’ home => ‘/home/thinknyx’, managehome => ‘true’ }
Syntax Check: “puppet parser validate /etc/puppetlabs/code/environments/production/manifests/thinknyx.pp”
# puppet parser validate thinknyx.pp Error: Could not parse for environment production: Syntax error at ‘gid’ at /etc/puppetlabs/code/environments/production/manifests/thinknyx.pp:4:5
cat /etc/puppetlabs/code/environments/production/manifests/thinknyx.pp user { ‘thinknyx’: ensure => ‘present’, uid => ‘700’, gid => ‘700’, home => ‘/home/thinknyx’, managehome => ‘true’ }
Run the parser validate again and this time there will not be any outputs, which indicates that the code syntax is correct and we can proceed with the smoke test to test the Puppet Code at more advanced levels.
# puppet parser validate thinknyx.pp
This is one of the most important step in the Puppet Coding to ensure the Puppet Code is having the standard and correct Puppet Coding Syntax or not. In our next post we will learn about the puppet smoke test and puppet run locally to ensure all is working as per our configured expectation.