move_obstructions behavior
"'Nick Anderson' via help-cfengine" <[email protected]> Wed, 12 Jul 2023 17:27:26 -0500
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Ron,
It's very helpful if you provide a small standalone policy that
demonstrates the behavior. I think this does it:
,----
| bundle agent __main__
| {
| files:
| "/tmp/move-obstructions.txt"
| content => "I am a plain file";
|
| "/tmp/move-obstructions.txt"
| move_obstructions => "false",
| link_from => default:ln_s( "$(this.promise_filename)" );
| }
`----
,----
| info: Created file '/tmp/move-obstructions.txt', mode 0600
| info: Updated file '/tmp/move-obstructions.txt' with content 'I am a plain file'
| error: Object '/tmp/move-obstructions.txt' is obstructing promise
| error: Unable to create link '/tmp/move-obstructions.txt' -> '/home/nickanderson/org/roam/daily/work/cfengine3-0cVlsi', failed to move obstruction
| error: Errors encountered when actuating files promise '/tmp/move-obstructions.txt'
`----
Based on your description alone, I can see the sense in *not* emitting
an *error* when `move_obstructions' is `false'. Indeed, if you are
explicit about not wanting to move something out of the way it seems a
bit silly to emit an error. However it also seems like this might be
better expressed in the policy to simply avoid making a promise in
that case.
This policy will create the link because there is no file there.
,----
| bundle agent __main__
| {
| files:
|
| "/tmp/move-obstructions.txt"
| delete => default:tidy;
|
| "/tmp/move-obstructions.txt"
| link_from => default:ln_s( "$(this.promise_filename)" ),
| if => not( fileexists( "/tmp/move-obstructions.txt" ) ),
| comment => "If there is nothing there, we want to have a symlink";
|
| }
`----
,----
| info: Deleted file '/tmp/move-obstructions.txt'
| info: Linked files '/tmp/move-obstructions.txt' -> '/home/nickanderson/org/roam/daily/work/cfengine3-gp5E8s'
`----
But what if there is a symlink, but it's pointing elsewhere? With
`move_obstructions => "false"' (the default) the symlink target won't
be fixed:
,----
| bundle agent __main__
| {
| files:
|
| "/tmp/move-obstructions.txt"
| delete => default:tidy;
|
| "/tmp/move-obstructions.txt"
| link_from => default:ln_s( "/etc/hosts" ),
| if => not( fileexists( "/tmp/move-obstructions.txt" ) ),
| comment => "If there is nothing there, we link the file to /etc/hosts";
|
| "/tmp/move-obstructions.txt"
| link_from => default:ln_s( "/etc/issue" ),
| if => islink( "/tmp/move-obstructions.txt" ),
| comment => "If it's a symlink, we fix the link";
|
| "/tmp/move-obstructions.txt"
| link_from => default:ln_s( "/etc/motd" ),
| if => islink( "/tmp/move-obstructions.txt" ),
| move_obstructions => "true",
| comment => "If it's a symlink, we fix the link";
|
| }
`----
,----
| info: Deleted file '/tmp/move-obstructions.txt'
| info: Linked files '/tmp/move-obstructions.txt' -> '/etc/hosts'
| error: Link '/tmp/move-obstructions.txt' points to '/etc/hosts' not '/etc/issue', but not moving obstructions
| error: Errors encountered when actuating files promise '/tmp/move-obstructions.txt'
| info: Overrode incorrect link '/tmp/move-obstructions.txt'
| info: Linked files '/tmp/move-obstructions.txt' -> '/etc/motd'
`----
So, what do you think? Do you still think that explicitly setting
`move_obstructions => "false"' should suppress the error about not
moving things out of the way?
Actually, looking at this and reviewing the docs, I think the link
should have been updated since that was already the same type of file.
Still, I think it's a bit better to be more explicit about the
conditions under which you want to actually make the promise. Based on
your description not wanting to replace a file or directory with a
link, but presumably wanting to fix a link that is pointing to the
wrong place I would probably write it like this:
,----
| bundle agent __main__
| {
| files:
| "/tmp/move-obstructions.txt"
| content => "I am a plain file";
|
| "/tmp/move-obstructions.txt"
| move_obstructions => "true",
| link_from => default:ln_s( "/etc/motd" ),
| if => islink( "$(this.promiser)" ),
| comment => concat( "If the file is a symlink, be sure to make sure it",
| " points to the correct place, if the file is a plain",
| " file or directory or socket etc ... then just leave it alone." );
| }
`----
--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/874jm8sr3l.fsf%40northern.tech.