Question

Hi I'm new to puppet and trying to work on a sample to copy files from one location to another location. Any sample script to do that?

Ex: I've my file at d:\temp\test.txt and I want to copy this file to E:\mycopy\ folder.

Was it helpful?

Solution

You can "ensure" that the file at target location exists and provide the file to be copied as source in file type. A partial code snippet only showing relevant parts:

file { 'E:\mycopy\folder\filename':
          ensure => present,
          source => "d:\temp\test.txt",
}

Check the documentation of file type here and how source attribute behaves here. Now this will work with a few caveats :

  • If you are using absolute file path as source - then the file should be present on agent machine
  • If you are serving file from Puppet's file server then the source file should be in appropriate location in puppet's file server.

But what is your exact purpose? Similar thing can be achieved with content attribute of file type or other attributes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top