Ask Your Question
0

Copy contents of symlink to directory

asked 2018-05-11 13:27:49 -0500

hsubraveti gravatar image

updated 2018-05-11 13:30:36 -0500

I am trying to copy contents of a symlink directory to a normal directory on Windows.

file { "copy symlink contents to directory":
    ensure             => directory,
    path               => "C:/Users/devacct/Desktop/puppet/puppet_dir2/", #directory
    source             => "C:/Users/devacct/Desktop/puppet/filessym/", #symlink
    recurse            => true,
    source_permissions => ignore,
    links              => 'manage',
    #ignore             => $ignore_files,
    #purge              => $purge,
    force              => true,
}

This fails with an error message.

Error: /Stage[main]/Custom::Profile::Symlink/File[copy symlink contents to directory]: Could not evaluate: Could not retrieve information from environment production source(s) file:/C:/Users/devacct/Desktop/puppet/filessym

Is it valid to give symlink path as a value to source attribute? If not, how do I achieve my objective? Link to Stackoverflow question

edit retag flag offensive close merge delete

Comments

`source` is a file/directory _on_ your Puppet server, where your puppet master runs (assuming you are in a client-server-environment). You can not copy files on the client using a file resource. You'd have to utilize an exec resource instead.

Kai Burghardt gravatar imageKai Burghardt ( 2018-05-13 03:55:06 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-05-31 00:25:50 -0500

joshc gravatar image

You can use the source parameter to copy files from a local filesystem. The important part is using links=follow, as manage means you want to manage the link itself. Here's an example, I have a directory with a file in C:\target, I have a symbolic link that points to the target, C:\link, and I can copy the contents (not the link) to C:\copy:

C:\>dir c:\target
 Volume in drive C has no label.
 Volume Serial Number is 807B-0CD6

 Directory of c:\target

05/30/2018  10:18 PM    <DIR>          .
05/30/2018  10:18 PM    <DIR>          ..
05/30/2018  10:18 PM                12 file.txt
               1 File(s)             12 bytes
               2 Dir(s)   5,916,864,512 bytes free

C:\>dir c:\link
 Volume in drive C has no label.
 Volume Serial Number is 807B-0CD6

 Directory of c:\link

05/30/2018  10:18 PM    <DIR>          .
05/30/2018  10:18 PM    <DIR>          ..
05/30/2018  10:18 PM                12 file.txt
               1 File(s)             12 bytes
               2 Dir(s)   5,916,864,512 bytes free

C:\>puppet resource file c:\link
file { 'c:\link':
  ensure => 'link',
  ctime  => '2018-05-30 22:16:23 -0700',
  group  => 'S-1-5-21-2397885826-1833024046-1055597067-513',
  mode   => '2000700',
  mtime  => '2018-05-30 22:16:23 -0700',
  owner  => 'S-1-5-32-544',
  target => 'C:\target',
  type   => 'link',
}

C:\>puppet resource file c:\copy ensure=directory recurse=true source=c:\link links=follow
file { 'c:\copy':
  ensure => 'directory',
}

C:\>puppet resource file c:\copy
file { 'c:\copy':
  ensure => 'directory',
  ctime  => '2018-05-30 22:23:05 -0700',
  group  => 'S-1-5-21-2397885826-1833024046-1055597067-513',
  mode   => '2000700',
  mtime  => '2018-05-30 22:23:05 -0700',
  owner  => 'S-1-5-32-544',
  type   => 'directory',
}

C:\>type c:\copy\file.txt
some content
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-05-11 13:27:49 -0500

Seen: 167 times

Last updated: May 31