11

Is there a (simple) way to have puppet use a file available on the internet for the Source property of a File?

eg:

file { "/home/text.txt":
  source => [
    "http://www.example.com/text.txt",
  ]
}
gunwin
  • 6,330
  • 3
  • 18
  • 22
  • If you value the integrity of your servers, at least use https. And use a more trustworthy domain cos you don't know who might be controlling that one... ummm... It gets murkier from here. – mc0e Oct 27 '14 at 14:39

3 Answers3

5

I'm writing an updated answer to notify future readers that now the File resource indeed implements the HTTP source.

From the docs:

source

A source file, which will be copied into place on the local system. This attribute is mutually exclusive with content and target. Allowed values are:

  • puppet: URIs, which point to files in modules or Puppet file server mount points.
  • Fully qualified paths to locally available files (including files on NFS shares or Windows mapped drives).
  • file: URIs, which behave the same as local file paths.
  • http: URIs, which point to files served by common web servers

So you can use the construct as you wrote it:

file { "/home/text.txt":
  source => "http://www.example.com/text.txt",
}
dr_
  • 1,035
  • 11
  • 19
  • 3
    as of Puppet version 4.4.0 (via ticket https://tickets.puppetlabs.com/browse/PUP-1072) – KJH Jan 07 '18 at 02:56
3

It's been requested as a feature for years... But you'd end up needing a custom function for this... or to use curl or wget. See Puppet Forge.

What's in text.txt?

ewwhite
  • 194,921
  • 91
  • 434
  • 799
  • txt.txt is just an example. I actually want to use it to pull Freeradius clients from an admin system. – gunwin Oct 28 '14 at 13:50
3

It's not possible out of the box right now:

source:

...

The available URI schemes are puppet and file. Puppet URIs will retrieve files from Puppet’s built-in file server

I ended up using define I found on the internet:

define remote_file($remote_location=undef, $mode='0644'){
  exec{ "retrieve_${title}":
    command => "/usr/bin/wget -q ${remote_location} -O ${title}",
    creates => $title,
  }

  file{$title:
    mode    => $mode,
    require => Exec["retrieve_${title}"],
  }
}

remote_file{'/home/text.txt':
  remote_location => 'http://www.example.com/text.txt'
}
Glueon
  • 3,514
  • 2
  • 22
  • 31