0

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.

brooks94
  • 167
  • 2
  • 5

2 Answers2

1

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.

mgorven
  • 30,615
  • 7
  • 79
  • 122
andrekeller
  • 499
  • 2
  • 5
0

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"],
  }
}
iamauser
  • 349
  • 2
  • 3
  • 12
  • 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... – andrekeller Mar 19 '13 at 09: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... – andrekeller Mar 19 '13 at 13:33