Forum: CFEngine Help
Subject: Re: edit_template variable expansion
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,25766,25790#msg-25790

It seems that the template is interpreted in the context of the edit_line 
bundle, so only variables local to the edit_line bundle would be visible 
locally; any other variables would be accessible in the same way as usual; by 
using the fully-qualified variable name (i.e. "$(bundle.varname)").  This is 
behavior consistent with any other bundle; unqualified variables are 
interpreted with an implicit "this".

So, if you want the template to use an unqualified / "local" variable rather 
than a fully-qualified variable, you'd have to either statically define it in 
the edit_lines bundle directly, or accept is as a parameter passed in to the 
edit_lines bundle:


$ cat edit.cf
bundle agent a {
files:
  "/tmp/deleteme"
    create    => "true",
    edit_line => template();
}
bundle edit_line template {
vars:
  "parameter" string => "Substituted Text!";
insert_lines:
  "/tmp/template"
    insert_type    => "file",
    expand_scalars => "true";
}

$ cat /tmp/template
This is some text
The inserted text is '$(parameter)'
Whee!

$ cf-agent -IKf ./edit.cf -b a
 >> Using command line specified bundlesequence
 -> Created file /tmp/deleteme, mode = 600
 -> Edited file /tmp/deleteme

$ cat /tmp/deleteme
This is some text
The inserted text is 'Substituted Text!'
Whee!


_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to