You can, however once a class is defined you must then apply it to the node using 'include'
[ 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: