Let's assume i have a site.pp like this:
class videoServer {
file { '/root/testFile' : ensure => present }
file { '/root/testFile2' : ensure => present }
file { '/root/testFile3' : ensure => present }
}
node s1.example.comf { include videoServer }
node s2.example.comf { include videoServer }
So i have a class videoServer with 3 in file resources and two nodes which include this class.
I am trying to figure out if there is an easy way to change resource's attributes or even totally exclude them. For example i want to exclude /root/testFile2 in the s2.example.com node. I would change it's ensure attribute to 'absent'. But what is the syntax for that if it really exists? If it's impossible how should i review the class to make it less painful?
Yes, i can you use class parameters like this:
class videoServer ( $fileState = present, $fileState2 = present,
$fileState3 = present ) {
...
file { '/root/testFile2' : ensure => $fileState2 }
...
...
node s2.example.com {
class { 'videoServer' : fileState2 = absent }
But that is really uncomfortable.
Maybe inheritance could help here but i do not think it's a good solution. The only difference in many nodes could be the absence of one file and i see no point in inheritance in that situation.
Best Answer
You can't remove a resource definition after it is declared, and you are right, class inheritance should be used very sparingly
I would use your class parameters example with hiera
Setting s2.example.com.yaml to