sanity check on file copy

13 views
Skip to first unread message

Louis Gillette

unread,
Apr 28, 2016, 4:53:50 PM4/28/16
to help-cfengine
I'm writing up a modular promise that will

A. check to see if a config file exists (sudoers in this example)
B. Delete that existing file only if it hasn't copied the replacement in from /inputs/standalone
C. Copy config file into place if it doesn't exist and set a class to disable future passes on the promise from deleting the file

What I'm drawing a blank on is setting a class based on the copy being fulfilled... would it be better to break the promise into two parts maybe? Link them sequentially?

######################################################################
bundle agent edit_sudoers
{

classes:
"sudoers_exists" expression => fileexists("/etc/sudoers")

files:

#cp sudoers file from /var/cfengine/inputs/standalone to /etc/sudoers if it doesn't exist
!sudoers_exists:
"/etc/sudoers"
copy_from => local_cp("$(sys.inputdir)/standalone/sudoers")
##### Set class if this action is fulfilled::"sudoers_copied"


#delete old sudoers file
sudoers_exists.!sudoers_copied
"/etc/sudoers"
delete => tidy;

}
######################################################################

Nick Anderson

unread,
Apr 28, 2016, 5:00:48 PM4/28/16
to Louis Gillette, help-cfengine
On 04/28/2016 03:53 PM, Louis Gillette wrote:
> I'm writing up a modular promise that will
>
> A. check to see if a config file exists (sudoers in this example)
> B. Delete that existing file only if it hasn't copied the replacement in
> from /inputs/standalone
> C. Copy config file into place if it doesn't exist and set a class to
> disable future passes on the promise from deleting the file

Is there a reason you want that specific behavior?

It might be simpler to promise that /etc/sudoers is a copy of
/inputs/standalone/etc/sudoers as long as /inputs/standalone/etc/sudoers
validates with visudo -c.

Generally unless you have some specific reason you shouldn't have to
first delete the file. You can simply promise that /etc/sudoers is a
copy of /inputs/standalone/etc/sudoers.


signature.asc
Reply all
Reply to author
Forward
0 new messages