Forum: CFEngine Help Subject: How-to insert multi line string at the top of file ? Author: juriskrumins Link to topic: https://cfengine.com/forum/read.php?3,27226,27226#msg-27226
My intent is to insert multi line string at the top of the file. So I've written following policy: ... "banner_numsign" string => "######################################################################################## # # WARNING! # This configuration file is managed by CFengine. Do not edit this file manually # ######################################################################################## ", comment => "Banner", handle => "common_def_vars_banner_numsign"; bundle edit_line insert_before_line(string,linenum) { insert_lines: "$(string)" location => before_line($(linenum)); } body location before_line(linenum) { before_after => "before"; select_line_number => "$(linenum)"; } bundle agent banner { files: "/root/test" handle => "file_banner", comment => "Insert banner in file", edit_line => insert_before_line("$(def.banner_numsign)",1); } And so when I execute this policy I have following result: # cat /root/test test1 test2 test3 # cf-agent R: --> undefined is my policy hub. R: --> CFE is running on cfdev R: Machine is hardware node with OpenVZ kernel. # cat /root/test ######################################################################################## # # This configuration file is managed by CFengine. Do not edit this file manually # WARNING! # ######################################################################################## test1 test2 test3 # So the lines gets inserted, but in the wrong oder, because CFEngine treats multi line string as a number of lines, rather than single object. Seems like I have to use insert_type attribute equal "preserve_block" for insert_lines promise. But I can't figure out how to do it. Can somebody point me to the right direction. Thank you. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine