This is an old revision of the document!


Puppet uses its own language in order to assure that changes a properly propagated, in this section, we will use DSL do automate a lot of tasks like:

  • Creating & Modify Users
  • Install & Configure Packages
  • Implement System changes

All that will be accross our infrastructure, which unfortunetely is only 3 servers:

  • PuppetMaster
  • PuppetSlave
  • PuppetSlaveTwo

So let's start with the basic understanding of how DSL works. Puppet architecture is comprised by:

  • Resources (e.g. in-build functions & operations: file, user, router, etc, perform individual tasks)
  • Classes (e.g. combination of resources, multiple small operations)
  • Manifest (e.g. definitions and declarion of puppet classes)
  • Modules (e.g. collection of files and manifest, example: mysql & jenkins module)

Once an object is created it has to go through the chain of release as follows:

So let's see that in an example:

To create a user, we will use a simple resource (e.g. function: user, to ensure that it exist)

Create

Create user

[root@puppetmaster demo]# vi demouser.pp
user { "julienandonov":
  ensure => "present",
}
:wq

Then we can validate the code, for syntax error using the parser:

Check

Check syntax

--If error exists
[root@puppetmaster demo]# puppet parser validate demouser.pp
Error: Could not parse for environment production: Syntax error at 'ensure' (file: /var/tmp/demo/demouser.pp, line: 2, column: 3)
[root@puppetmaster demo]# 

-If it no error exists
[root@puppetmaster demo]# puppet parser validate demouser.pp
[root@puppetmaster demo]#

Test

We can test if the application of the change will be possible:

Test

[root@puppetmaster demo]# puppet apply --noop demouser.pp
Notice: Compiled catalog for puppetmaster.example.com in environment production in 0.03 seconds
Notice: /Stage[main]/Main/User[julienandonov]/ensure: current_value 'absent', should be 'present' (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 event
Notice: Stage[main]: Would have triggered 'refresh' from 1 event
Notice: Applied catalog in 0.01 seconds

Finally we can apply the change:

Apply

Apply

[root@puppetmaster demo]# puppet apply demouser.pp
Notice: Compiled catalog for puppetmaster.example.com in environment production in 0.01 seconds
Notice: /Stage[main]/Main/User[julienandonov]/ensure: created
Notice: Applied catalog in 0.20 seconds
[root@puppetmaster demo]#
  • puppet_dsl.1605864212.txt.gz
  • Last modified: 2020/11/20 09:23
  • by andonovj