yarlagadda ramya
2013-Feb-18 07:07 UTC
[Puppet Users] Can we write many classes in a single manifest
Hi all, Can we write many classes in a single manifest and apply that manifest?? For example i have created manifest, file1.pp and it includes the following: class one{ exec{"--" command => " ", cwd => " ", } } class two{ exec{"--" command => " ", cwd => " ", } } now can i write a manifest like this and apply it? Can any one pls help me with it? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Keiran Sweet
2013-Feb-18 10:40 UTC
[Puppet Users] Re: Can we write many classes in a single manifest
Hi There, You can, however once a class is defined you must then apply it to the node using ''include'' Example: [ Keiran ~]$ cat /tmp/example.pp class class1 { exec { exec1 : command => "/bin/touch /tmp/${title}", } } class class2 { exec { exec2 : command => "/bin/touch /tmp/${title}", } } include class1 include class2 [ Keiran ~]$ puppet apply /tmp/example.pp notice: /Stage[main]/Class2/Exec[exec2]/returns: executed successfully notice: /Stage[main]/Class1/Exec[exec1]/returns: executed successfully notice: Finished catalog run in 0.17 seconds [ Keiran ~]$ ls -al /tmp/ |grep -i class -rw-r--r-- 1 Keiran Keiran 0 Feb 18 10:27 class1 -rw-r--r-- 1 Keiran Keiran 0 Feb 18 10:27 class2 [ Keiran ~]$ Defining multiple classes in a single manifest for non-testing/learning may not always be deemed as best practice, It might be worth having a read of the following documentation: - http://docs.puppetlabs.com/puppet/2.7/reference/lang_classes.html - http://docs.puppetlabs.com/guides/style_guide.html Hope this helps, K On Monday, February 18, 2013 7:07:39 AM UTC, yarlagadda ramya wrote:> > Hi all, > > Can we write many classes in a single manifest and apply that manifest?? > For example i have created manifest, file1.pp and it includes the > following: > > class one{ > exec{"--" > command => " ", > cwd => " ", > } > } > > > class two{ > exec{"--" > command => " ", > cwd => " ", > } > } > > now can i write a manifest like this and apply it? > > Can any one pls help me with it? >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Feb-18 14:37 UTC
[Puppet Users] Re: Can we write many classes in a single manifest
On Monday, February 18, 2013 1:07:39 AM UTC-6, yarlagadda ramya wrote:> > Hi all, > > Can we write many classes in a single manifest and apply that manifest?? >Yes and no. You can write many classes in the same manifest file, but you cannot leverage their colocation in the same file to assign all of them to the same node at once.> For example i have created manifest, file1.pp and it includes the > following: > > class one{ > exec{"--" > command => " ", > cwd => " ", > } > } > > > class two{ > exec{"--" > command => " ", > cwd => " ", > } > } > > now can i write a manifest like this and apply it? > > Can any one pls help me with it? >You should put all your classes in modules, and lay them out in the way the autoloader expects. Example: modules/mymodule/manifests/one.pp: ------ class mymodule::one { # resources ... } modules/mymodule/manifests/two.pp: ------ class mymodule::two { # resources ... } Note the correspondences between module name ("mymodule") and directory, and between class names and file names. Those are significant. If you want a simple, reusable way to apply both of those together to the same node, then create a class for it. If the two (or more) belong to the same module, then you might be looking for a module main class: modules/mymodule/manifests/init.pp: ------ class mymodule { include ''mymodule::one'' include ''mymodule::two'' } Note that that one is special: the fully-qualified name of the class is the same as the name of the module, and it (for that reason) is recorded in a file named ''init.pp'' in the module''s manifests directory. To apply both to node "mynode", just assign class ''mymodule'' to that node: node ''mynode'' { include ''mymodule'' } John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.