Forum: CFEngine Help Subject: Re: About "new" templates correct usage or limitations Author: th Link to topic: https://cfengine.com/forum/read.php?3,26723,26812#msg-26812
One more thing I'm noticing : - edit_template seems to start emptying the file, so execution time is the same for each run, again quite too long for big files since it checks for duplicate lines/ - expand_template is quite faster if the file does not exist, but it it does, it checks for already inserted lines, which can make subsequent runs quite long as well With the a template file such as : # wc -l test.tmpl 515 test.tmpl # cat test.tmpl This is the test template line number 1 This is the test template line number 2 # Comment # Comment # Comment This is the test template line number 3 This is the test template line number 4 VAR1 = $(test_tmpl.var1) This is the test template line number 5 This is the test template line number 6 VAR2 = $(test_tmpl.var2) This is the test template line number 7 [...] This is the test template line number 500 1. Using edit_template body common control { bundlesequence => { "test_tmpl" }; inputs => { "cfengine_stdlib.cf" } ; } bundle agent test_tmpl { vars: "dir" string => "/root/TEMPLATES" ; "test_tmpl" string => "test.tmpl" ; "test" string => "test" ; "var1" string => "VALUE1" ; "var2" string => "VALUE2" ; files: "$(dir)/$(test)" edit_template => "$(dir)/$(test_tmpl)", create => "true"; } 1.a) first run, starting with a non-existent file : # ls -l test ls: cannot access test: No such file or directory # time cf-agent -K -f ./test-templates.cf real 0m0.193s user 0m0.183s sys 0m0.011s 1.b) second run : # ls -l test -rw------- 1 root root 20931 Jul 31 18:51 test # time cf-agent -K -f ./test-templates.cf real 0m0.192s user 0m0.179s sys 0m0.015s 2. Using expand_template # cat test-templates.cf body common control { bundlesequence => { "test_tmpl" }; inputs => { "cfengine_stdlib.cf" } ; } bundle agent test_tmpl { vars: "dir" string => "/root/TEMPLATES" ; "test_tmpl" string => "test.tmpl" ; "test" string => "test" ; "var1" string => "VALUE1" ; "var2" string => "VALUE2" ; files: "$(dir)/$(test)" edit_line => expand_template("$(dir)/$(test_tmpl)"), create => "true"; } 2.a) first run, starting with an empty file # ls -l test ls: cannot access test: No such file or directory # time cf-agent -K -f ./test-templates.cf real 0m0.045s user 0m0.031s sys 0m0.014s 2.b) second run # ls -l test -rw------- 1 root root 20960 Jul 31 18:58 test # time cf-agent -K -f ./test-templates.cf real 0m0.094s user 0m0.083s sys 0m0.009s So, I'm sorry but I still don't quite understand what is the best way to promise a whole, possibly large file. Seems to me that either edit_template or expand_template could be too long for "large" files and using edit_lines with iteration over the content of an array would require building manually a huge array (even if it can then take advantage of the auto-looping feature)... Thanks for your patience... -- TH _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine