Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have a server (managed by puppet) that generates a file once per day. Is there an approach I could use to make puppet do the following:

  • Recognize that the file is there on server A
  • Upload it to the puppet master
  • Ensure its existence on puppet-managed server B
  • Reload a service on server B

It's really the recognizing and uploading that I'm not clear on. I think I understand how to ensure the existence on server B and reload the service.

Any patterns or documentation would be helpful. Thanks.

share|improve this question
    
does it need to be on the master? –  Mike Mar 18 '13 at 16:42
add comment

2 Answers

I'd have a look into exported resources.

You could define an additional resource using a custom fact as source for the file contents:

node servera {
    @@file { "/generated/file"
        ensure => present,
        content => $::myspecialfilecontent
        tag => myspecialfile,
    }
}

and realise the resource on serverb:

node serverb {
    File <<| tag == 'myspecialfile' |>> {
        notify => Service["your_service"],
    } 
}

the custom puppet fact could look like follows (put it in a modules/.../lib/facter/myspecialfilecontent.rb file and enable pluginsync):

filename = '/generated/file'
Facter.add(:myspecialfilecontent) do
    setcode do
        if File.file?(filename)
            File.read(filename)
        end
    end
end

you need storeconfigs = true (puppetdb) for that though.

This is not a very clean solution but it could work.

share|improve this answer
add comment

Let's assume that you have a common class or node (like the default) that applies to all the nodes managed by puppet.

Here you create the policy to manage the file created daily, but only a virtual resource.

node default {
  $fsufix = strftime("%y_%m_%d")
  @file { "everyday_file" :
    path => "/scratch/usern/file_${fsufix}",
    ensure => present,
  }
}

Then for the serverA, you just need to check whether that file is present by realizing the virtual resource we just created earlier :

node 'serverA' inherits default {
  realize(File["everyday_file"])
}

After this you want serverB to do the same as serverA plus refresh a service if the file is created or modified :

node 'serverB' inherits default {
  realize(File["everyday_file"])
  service { "mysqld" :
    ensure => running,
    hasrestart => true,
    subscribe => File ["everyday_file"],
  }
}
share|improve this answer
    
are you sure this will catch the content of the file? IMHO when you specify a file without source/content puppet just ensures the file is there but does not care about its content... –  rbtux Mar 19 '13 at 9:11
    
question of OP has nothing about the content of the file. In any case, since this file is being produced everyday, I believe the content might be different and may need some kind of template, but that's another question... –  iamauser Mar 19 '13 at 12:59
    
as far as I understood it the file itself is generated by an application and not from within puppet... But of course I could be wrong... –  rbtux Mar 19 '13 at 13:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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