Puppet: Writing multiple manifest for multiple clients

How to use multiple manifests in Puppet ?

Puppet always starts compiling with either a single manifest file or a directory of manifests that get treated like a single file. This main starting point is called the main manifest or site manifest.

If we need to write multiple files, then for  earlier versions of Puppet , we can use the import function to call  the other manifests in site.pp

             import "../classes/*"
             import "../nodes/*"


In Puppet 4, the import function is deprecated . I was getting the error below

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Use of 'import' has been discontinued in favor of a manifest directory. See http://links.puppetlabs.com/puppet-import-deprecation at /apps/wps/puppetlabs/code/environments/production/manifests/site.pp:2:1 on node aus-lnaswgp-002.wiley.com

The solution is to put all the main manifests in Puppet manifests directory as per output of below command. 


       # puppet config print manifest
      /etc/puppetlabs/code/environments/production/manifests


In the above command , we will copy the nodes and classes folder to manifests directory. 



Accessing the manifest from Client:

Now to access the manifest from client , we will create the manifest file based on the hostname or FQDN of the client.

So , if the client name is node-002,then the manifest name for this host can be any of the following

  node-002.example.com, node-002.example,node-002,   
  NODE-002.example.com,NODE-002.example,NODE-002' on node   
  node-002.example.com

If the hostname does not match , when we will execute the puppet apply command , it will suggest what should be the manifest name with the below error . 


Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find node statement with name 'default' or 'node-002.example.com, node-002.example, node-002, NODE-002.example.com, NODE-002.example, NODE-002' on node node-002.example.com
We just need to add a .pp after the manifest name. If there are multiple client nodes, then by following the above naming convention,we can create the manifest for the other node.We can do this for all other nodes. The manifests directory will look like this after we prepared the manifests for all clients. 

$ls /apps/wps/puppetlabs/code/environments/production/manifests/nodes    
node-001.example.com.pp  node-002.example.com.pp node-003.example.com.pp  node-004.example.com.pp  node-005.example.com.pp node-006.example.com.pp  node-007.example.com.pp

Now we will start applying the manifests by executing the below command from the respective servers, 

# puppet agent  -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node-002.example.com








......
......







Comments

Popular Posts