slist in templates

45 views
Skip to first unread message

Denis

unread,
Jul 24, 2014, 10:02:04 AM7/24/14
to help-c...@googlegroups.com
Hello,

I need to make 3 similar files, with only one option different.
bundle agent my_agent {

vars:
    "my_list_var" slist => {"l1","l2","l2"};

files:
    "/etc/file.$(my_list_var).conf"
          perms => m("0640"),
          create => "true",
          edit_defaults => empty,
          edit_line => expand_template("/tmp/my_file.tmpl");

}

inside file I have value

var = $(my_agent.my_list_var)

After run I get 3 files, as intended /etc/file.l1.conf and so on, but inside I get "$(my_agent.my_list_var)"

Can anyone point me to right direction please ?

Thanks in advance.

--
Denis

Neil Watson

unread,
Jul 24, 2014, 10:26:25 AM7/24/14
to help-c...@googlegroups.com
Try using the newer edit_template instead of edit_line.

https://docs.cfengine.com/docs/3.5/reference-promise-types-files.html#edit_template
example:
http://evolvethinking.com/template-configuration-files-using-cfengine/

--
Neil H Watson
Compliance reporting with CFEngine Community http://evolvethinking.com/products/delta-reporting/
Simplify CFEngine with EFL http://evolvethinking.com/evolve-thinkings-free-cfengine-library/
VIM and Cfengine https://github.com/neilhwatson/vim_cf3
CFEngine support and training from Evolve Thinking, http://evolvethinking.com

Ed

unread,
Jul 24, 2014, 10:53:04 AM7/24/14
to help-c...@googlegroups.com
I would also use templates for this kind of task, as mentioned by Neil.

If you must use expand_template, you could what you want with the methods promise:
bundle agent my_agent
{
  vars
:
     
"my_list_var"          slist => { "I1", "I2", "I3" };


  methods
:
     
"my_file_$(my_list_var)"          usebundle => my_file("$(my_list_var)");
}

bundle agent my_file
(filename)
{
  files
:
     
"$(this.promise_dirname)/$(filename).txt"

             create
=> "true",
      edit_defaults
=> empty,

          edit_line
=> expand_template("$(this.promise_dirname)/my_file.tmpl");
}

Then put

var = $(my_file.filename) in template

in your template.

Ed

Denis

unread,
Jul 27, 2014, 5:31:03 PM7/27/14
to help-c...@googlegroups.com
Thanks guys.
Ed's way was best one for my task.
Reply all
Reply to author
Forward
0 new messages