1

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.

1

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

node s1.example.comf { include videoServer }
node s2.example.comf { include videoServer }

Setting s2.example.com.yaml to

videoServer::fileState2: absent
  • As i understand yamls are related to Hiera, right? I haven't worked with it yet, but thanks for giving a direction. So there is no ruby-puppet syntax i could use to do the same thing within site.pp in a node section? – Glueon Oct 6 '14 at 18:26
  • correct, the yaml goes into /etc/puppet/hieradata and you'd need to correctly configure Hiera, which is easy enough. You can use the site.pp example you added at the end of your question, but it is easier to manage with hiera. – csanchez Oct 7 '14 at 9:27
1

I found a solution. Actually what I wanted to accomplish is possible using a spaceship <| |> operator.

So if I want to change a desired state of the /root/testFile2 file only for the s1.example.com node I should do something 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 
    File <| title == '/root/testFile2' |> { ensure => absent }
}

node s2.example.comf { include videoServer }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.