Puppet Manifests
• Manifests are files that store specific configurations for resources
• Manifests for every resource are located on the Puppet master
• Each manifest ends with a .pp file extension
• Puppet site.pp manifest has global configurations that are applicable to all nodes
• Site manifests have node specific code as well
• Node definition is Puppet code included in catalog of nodes matching that node definition
• This allows you to assign specific configurations to specific nodes
• Manifests grouping several resources can also be created
• A class can be used to apply resources to specific nodes
Create a file file.pp in master terminal window and add the following text to it.
cd /etc/puppet/manifests
nano file.pp
file{“/root/test-file.txt” :
ensure => ‘file’,
content => ‘This is a file managed by Puppet’,
}
ls -l
Go to the master terminal and run the following command. When you will execute this command, Puppet will apply the file manifest and create the test-file.txt in the root.
puppet apply file.pp
Change directory to root and check for this file. The contents of the file will have what we defined earlier in file.pp
ls -l /root
less /root/test-file.txt
Go to the master terminal and run this command again. This time you will see it will not compile the catalog because there is no change to it. Puppet saves the last state of catalog and unless the catalog changes, Puppet keeps applying the same catalog without compilation.
puppet apply file.pp
Go to master window again and make modifications to the file.pp and run the apply command again
nano file.pp
file{“/root/test-file.txt” :
ensure => ‘file’,
content => ‘This is a file managed by Puppet in root directory’,
}
puppet apply file.pp
This will again compile the catalog again because there have been changes to the file.pp and then apply the catalog. It will also over write the test-file.txt with new content.
If you make local changes to test-file.txt and run the puppet apply command again, it will over write your local changes with what is in file.pp
Also try the following command
puppet apply file.pp --noop
Create a file site.pp in master terminal window and add the following text to it. For file /etc/motd: we will ensure the file is present or not; if present we will do the required changes; if needed we will change file permissions
cd /etc/puppet/manifests
nano site.pp
node default {
file {'/etc/motd':
content=> "this is my testing content',
}
Run the following command in the agent terminal window. This will create a file motd in folder /etc. Here we are using site.pp and nodes to apply changes to.
puppet agent -t
Modify the file site.pp in master terminal window and add the following text to it. For service postfix: we will ensure the service exists or not; if exists ensure its running or not; if running, stop it
cd /etc/puppet/manifests
nano site.pp
node default {
file {'/etc/motd':
content=> "this is my testing content',
}
service {'postfix':
ensure => 'stopped',
enable => 'false',
}
}
Comments
Post a Comment