Forum: CFEngine Help Subject: Re: "real" templates Author: toddnni Link to topic: https://cfengine.com/forum/read.php?3,23837,23846#msg-23846
I use few simple "tricks" with edit_line promises. For example lets consider a template # Some header with scalar $(mybundle.first_scalar) Something that is always defined $(mybundle.optional1) $(mybundle.optional2) and a bundle bundle agent mybundle { vars: any:: "first_scalar" string => "$(somewhere_else.variable)"; print_line_1:: "optional1" string => "A string that will now appear."; !print_line_1:: "optional1" string => ""; # -> Empty line print_servers:: "server_list" slist => { "server1", "server2", "server3" }; "temporary_string" string => join(" iburst$(const.endl)server ","server_list"); "optional2" string => "server $(temporary_string) iburst"; !print_servers:: "optional2" string => ""; files: any:: "path/to/file" create => "true", edit_defaults => empty, edit_line => expand_template("path/to/template"); } First variables can be defined empty when line is not needed. Second one can use join to creatively join lists (I think this is the trickery that Neil mentioned). Optional2 would finally be server server1 iburst server server2 iburst server server3 iburst I'm not sure, but new concat function might also work string => concat("server ", join(" iburst$(const.endl)server ", "server_list"), " iburst") However to create more complicated lines like server server1 iburst something_dependent_on_server1 server server2 iburst something_dependent_on_server2 server server3 iburst something_dependent_on_server3 I would suggest to use insert_lines promises with select_region. Mark mentioned this too. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine