Forum: CFEngine Help Subject: Re: Ownership issue with output files Author: zzamboni Link to topic: https://cfengine.com/forum/read.php?3,24996,25003#msg-25003
Like Nick said, reports: promises are not meant to be used to create files - they are for printing messages. For editing files you should use a files: promise with an edit_line attribute. Your create_ssh_dir bundle can be rewritten as follows: bundle agent create_ssh_dir(user) { vars: "index" slist => getindices("$(user)"); classes: "create_dir" expression => userexists("$(index)"); files: linux:: "$($(user)[$(index)])/.ssh/." perms => mug("700","$(index)","$(index)"), move_obstructions => "true", create => "true"; "$($(user)[$(index)])/.ssh/authorized_keys" perms => mug("600","$(index)","$(index)"), move_obstructions => "true", edit_defaults => empty, create => "true", edit_line => append_if_no_line("$($(user)[$(index)])"); "$($(user)[$(index)])/.ssh/id_rsa" perms => mug("600","$(index)","$(index)"), move_obstructions => "true", edit_defaults => empty, create => "true", edit_line => append_if_no_line("$($(user)[$(index)])"); } Note two main things: - The commands: promises to remove the files are not necessary. It's much better to use the edit_defaults => empty attribute, which will redo the files from scratch, but only rewrite them if there's any change in them. - Adding the content is done with the edit_line attribute in the files: promises. Best regards, _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine