Puppet Http Source for files

Sometimes you would like to use an http URL as the source file for puppet; while it's being discussed since long, no implementation has been created so far.

Of course it would be better to periodically download the file from its http source to the puppet master, and then use puppet file server to send such file to our client; but that's impractical in some contexts, especially if you're using your puppet in headless mode, i.e. without a master. In such situations you may really want to source files from http, without redownloading them if they haven't changed.

I found a good way to do it is to use the excellent [wget] http://www.gnu.org/software/wget/) command line tool.

This is an example of what I use to keep my installation of Jenkins up to date:

class jenkins {
	exec { "/usr/bin/wget --timestamping http://mirrors.jenkins-ci.org/war-stable/latest/jenkins.war":
		alias => "jenkinslatest",
		cwd => "/tmp",

	file { "/opt/tomcat7/latest/webapps/jenkins.war":
		ensure => present,
		source => "/tmp/jenkins.war",
		alias => "jenkinswar",
		require => Exec["jenkinslatest"] }


The timestamping flag will let wget check the remote server for file modification time; if file hasn't changed, it won't be redownloaded.

Just choose a proper directory for temporary downloads (tmp is volatile and gets sometimes cleaned up at runtime as well), make sure the server properly sets the Last-Modified header and remember to refresh your other resources when files change, and you're done.