Symbolic link overwritten by seed_rcp

13 views
Skip to first unread message

Bob

unread,
Nov 17, 2016, 9:12:41 AM11/17/16
to help-cfengine
I have a recipe to install a file if nothing exists already. However, if a symbolic link is there (and not broken) the seed_rcp() seems to remove the symbolic link and overwrite the target file.

  myhost::
    "/etc/file.conf"
    perms         => mog("0664", "root", "staff"),
    copy_from     => seed_rcp("$(globals.copy_root)/etc/file.conf-myhost", "$(globals.server)"),
    action        => immediate;
 
body copy_from seed_rcp(from,server)
{
servers     => { "$(server)" };
source      => "$(from)";
compare     => "exists";
copy_backup => "false";
preserve    => "true";
}


Is there a way to avoid this behavior?

Neil Watson

unread,
Nov 17, 2016, 9:37:17 AM11/17/16
to help-cfengine
Try using isplain and islink to test the file.

classes:

"no_file" expression => isplain( "/tmp/foo" );
"no_link" expression => islink( "/tmp/foo" );
"copy_file" expression => no_file.no_link;

files:
copy_file::
"yada, yada, yada"
....

--
Neil H Watson @neil_h_watson
CFEngine reporting: https://github.com/neilhwatson/delta_reporting
CFEngine policy: https://github.com/neilhwatson/evolve_cfengine_freelib
CFEngine and vim: https://github.com/neilhwatson/vim_cf3

Christian Linden

unread,
Nov 17, 2016, 10:44:18 AM11/17/16
to help-cfengine, cfen...@watson-wilson.ca
a bit shorter:

classes: 
   "no_file" expression => isplain( "/tmp/foo" ); 
   "no_link" expression => islink( "/tmp/foo" ); 
files: 
   no_file.no_link:: 
      "yada, yada, yada"

=)

Thanks for all your hints, Neil. I didn't know about the no_ expression types, always used the !expression-results.
Those here have many advantages!

c

Neil Watson

unread,
Nov 17, 2016, 10:49:43 AM11/17/16
to help-cfengine
I might have gotten that wrong. I think you want:

classes:

"no_file" not => isplain( "/tmp/foo" );
"no_link" not => islink( "/tmp/foo" );

# I prefer to keep this as it's more meaningful to the reader than a
# compound expression.
"copy_file" expression => no_file.no_link;

files:
copy_file::
"yada, yada, yada"

Reply all
Reply to author
Forward
0 new messages