Defined Types vs Parameterised Classes, when to use what?

Gourav Shah
A free video tutorial from Gourav Shah
Premium Instructor| 35k+ students| Devops Trainer and Author
4.2 instructor rating • 14 courses • 37,995 students

Learn more from the full course

Mastering Puppet the devops way by School of DevOps®

The most comprehensive Puppet course. Learn to write Infrastructure as a Code and manage it at scale with Puppet

08:05:30 of on-demand video • Updated July 2020

  • Infrastructure as a Code and related concepts e.g. idempotence, convergence
  • Puppet's DSL and best practices to write Manifests, Modules, Node Classification etc.
  • Create dynamic, data driven modules with Parameters and Templates
  • Setup Puppet Master and Nodes and apply configurations with centralised configuration management system
  • Integrate with Continuous Integration tool (CircleCI) and deploy applications with Puppet
  • Managing multiple environments e.g. Dev, Stage, QA, Production
  • Externalising properties with Hiera
  • Roles and Profile Design Patterns
  • Overview of Puppet Enterprise
English [Auto] So to understand the difference between a defined type and Abara MacRae's class which are very very similar and going to compare those side by side and this is for a WordPress model that I have downloaded from the public for so if you group of students or for Wordpress This is the first module that you see here that's Boughner what press and what we have here are two different manifest. One is this and it does. The second is this instance that BP and if you compare it side by side what you see on the right hand side is a parametrized class which starts with the key word Kalas class and the name of the class on the left hand side you have defined type or a definition and it starts with what press instance right. So apart from Klasky word and a defined key word here. If you compare the definition of a defined type just parametrized class. It looks almost similar and sort of you cannot differentiate between the two by looking at the definition because it bought. Except that it does not bode well. We'll have a model first but we'll map have the same manifest done that last naming convention so the naming convention is similar but defined divergence by race classes. Why do we see what presence in this instance or P-P this is indeed a or b b if it had been a different first it would have been what press can call it something which is similar. So the only different differentiation here you see is defined in class that does not tell us why do we need this construct specifically because it's sort of similar to BARMAK race classes alone and it will go and have some logic in the form of resources or I might call some other classes or definitions as well. Right. So by looking at it we can identify the difference. Now let's look at the usage. Now this is for the bottom race class either this or this. This is how we define. So we've already learned about creating about image. Rosalind Tom-Kat And if you look at the vigorish and this goes inside your definition is what we call it in sort of include lines and that's the part of which riskless on the other hand. What you see here is for the definition or that defined right now if you look at the differences here and here now you should be able to identify why we need a defined type here and if you look at this part what you see here are two instances of what press Anchal instance with two different Bhatt's two different usernames and passwords. So everything is different. So it seems to be creating multiple instances of what braes And that's exactly the fundamental difference between a defined type and a pattern we device classes because defined type allows you to create multiple instances of something it could be multiple Tom-Kat instances multiple qualified deployment that we're going to do multiple instances of what is multiple instances of users. Anything that you want to do multiple times you use a defined type whereas classes are singletons classes are system wide. So if you want to install something you'll typically install it only once in guess of what price it's a unique model because it allows you to either create one single instance of Wordpress using a class or multiple instances using this defined type. Now how can you add into other defined type. So even if we had one instance you should be able to identify or define type by the way it has been declared here. If it is a class it will always always always start with the Klasky what. And then the name of the class. Whereas if it is a defined type it will start with the definition that actually and that will be the name of the model call and call something. And if you see something like this it is definitely rest assured is a defined type and this is an instance of a defined by. This is another instance right so that will help you identify a defined type versus a part McCrae's class. And we just looked that vite of any do you really find that is if you want to create multiple instances of something in the next lesson we're going to start using this defined type to set up a load balancer.