The example files are all in the tests/units of the source tarball
Mark
Jesse Becker wrote:
> On Thu, Feb 18, 2010 at 01:14:16AM -0500, Mark Burgess wrote:
>>
>> Jesse,
>>
>> you should use the fully qualified name $(tmpl.varA) for the variables
>> in the file, as
>> they get processed in a different bundle and are therefore not "local"
>
> This works, thanks:
>
> [r...@host tmp]# cat /tmp/template
> The first variable: ${test.varA}
> And the second: ${test.varB}
>
> [r...@host tmp]# cat /tmp/expanded
> The first variable: This is value Alpha
> And the second: This is value Bravo
>
> The documentation posted online does not make this clear (and would have
> saved me several hours of time yesterday), and the limited examples I
> found online for using this method do not include mention of the full
> qualification for the variables either:
>
>
> http://www.cfengine.org/manuals/cf3-reference.html#expand_005fscalars-in-insert_005flines
>
>
> http://project.iu.hio.no/viewvc/trunk/tests/units/unit_template.cf?view=markup&root=Cfengine-3
>
> https://cfengine.org/pipermail/help-cfengine/2009-November/006706.html
>
> Generally speaking, having more complete examples, including any
> "supporting files" like sample template filess, would be a big help to
> everyone. Perhaps these would be suitable for posting on the cfwiki?
>
>> Jesse Becker wrote:
>>> I'm trying to get a basic templating system working for several files,
>>> and expand_scalars doesn't seem to work. I've found serveral references
>>> to other people having success with this, so I assume I've done
>>> something wrong. I'm running the cfengine 3.0.3 community RPM build.
>>>
>>> Here's the basic code:
>>>
>>> bundle agent tmpl {
>>>
>>> vars:
>>> hostname::
>>> "varA" string => "This is value Alpha";
>>> "varB" string => "This is value Bravo";
>>>
>>> files:
>>> hostname::
>>> "/tmp/template"
>>> copy_from =>
>>> update_copy("${g.repo}/template",${g.policy_server});
>>>
>>> "/tmp/expanded"
>>> create => 'true',
>>> edit_defaults => empty,
>>> edit_line => expand_template("/tmp/template");
>>> }
>>>
>>> Both 'empty' and 'expand_template come from cfengine_stdlib.cf file
>>> posted a few days ago.
>>>
>>> The content of the 'template' file is simply two lines:
>>>
>>> The first variable: ${varA}
>>> And the second: ${varB}
>>>
>>>
>>>
>>> I expect, after the expansion is done to have a file that looks like
>>> this:
>>>
>>> The first variable: This is value Alpha
>>> And the second: This is value Bravo
>>>
>>>
>>> But alas, the two files are identical after running cf-agent.
>>>
>>> Below is the relevant output from --verbose. The template file copies
>>> over without problems, and the 'expanded' file is created, but no
>>> interpolation appears to be done.
>>>
>>> TIA,
>>>
>>>
>>> cf3 Promise made by: /tmp/template
>>> cf3 .........................................................
>>> cf3
>>> cf3 -> Copy file /tmp/template from
>>> /usr/local/cfengine3/data/Packages/template check
>>> ... <snip>
>>> cf3 -> /tmp/template wasn't at destination (copying)
>>> ... <snip>
>>> cf3 -> New file /tmp/template.cfnew transmitted correctly - verified
>>> ... <snip>
>>>
>>> cf3 .........................................................
>>> cf3 Promise handle:
>>> cf3 Promise made by: /tmp/expanded
>>> cf3 .........................................................
>>> cf3
>>> cf3 -> Using literal pathtype for /tmp/expanded
>>> cf3 -> No mode was set, choose plain file default 600
>>> cf3 -> Created file /tmp/expanded, mode = 600
>>> cf3 Build file model from a blank slate (emptying)
>>> cf3 -> Handling file edits in edit_line bundle expand_template
>>> cf3
>>> cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>>> * * *
>>> cf3 BUNDLE expand_template( {'/tmp/template'} )
>>> cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>>> * * *
>>> cf3
>>> cf3 ? Augment scope expand_template with templatefile
>>> cf3 ?? Private class context
>>> cf3
>>> cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
>>> cf3 insert_lines in bundle expand_template
>>> cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
>>> cf3
>>> cf3 .........................................................
>>> cf3 Promise handle:
>>> cf3 Promise made by: /tmp/template
>>> cf3 .........................................................
>>> cf3
>>> cf3 -> Inserting the promised line "The first variable: ${varA}"
>>> into /tmp/expanded after locator
>>> cf3 -> Inserting the promised line "And the second: ${varB}" into
>>> /tmp/expanded after locator
>>> cf3 ?? Private class context
>>> cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
>>> cf3 insert_lines in bundle expand_template
>>> cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
>>> cf3
>>> cf3
>>> cf3 .........................................................
>>> cf3 Promise handle:
>>> cf3 Promise made by: /tmp/template
>>> cf3 .........................................................
>>> cf3
>>> cf3 -> This promise has already been verified
>>> cf3 ?? Private class context
>>> cf3
>>> cf3
>>> cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
>>> cf3 insert_lines in bundle expand_template
>>> cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = =
>>> cf3
>>> cf3
>>> cf3 .........................................................
>>> cf3 Promise handle:
>>> cf3 Promise made by: /tmp/template
>>> cf3 .........................................................
>>> cf3
>>> cf3 -> This promise has already been verified
>>> cf3 -> Saving edit changes to file /tmp/expanded
>>> cf3 Edited file /tmp/expanded
>>>
>>>
>>>
>>
>> --
>> Mark Burgess
>>
>> -------------------------------------------------
>> Professor of Network and System Administration
>> Oslo University College, Norway
>>
>> Personal Web: http://www.iu.hio.no/~mark
>> Office Telf : +47 22453272
>> -------------------------------------------------
>
--
Mark Burgess
-------------------------------------------------
Professor of Network and System Administration
Oslo University College, Norway
Personal Web: http://www.iu.hio.no/~mark
Office Telf : +47 22453272
-------------------------------------------------
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine