[et-mgmt-tools] Looping through possibilities in a "snippet"

Sandor W. Sklar ssklar at stanford.edu
Sun Apr 6 18:57:49 UTC 2008



I'd like to use snippets in my kickstart file for selecting things  
like partitioning, packages, and post portions based on either user- 
provided ksmeta variables or the Cobbler-provided variables.   
Unfortunately, I know very little Python, and my googling around for  
Cheetah examples of what I'd like to do has been less then fruitful.

Example:  In my /etc/cobbler/rhel5xen.ks kickstart template, I've  
got ...

%packages
SNIPPET::packages_select


What I'd like that file /usr/lib/cobbler/snippets/packages_select is  
to do something like (in psuedo-code here; if I could write the "real"  
code, I wouldn't be asking.  :-)


====================================

$package_snip_dir = /var/lib/cobbler/snippets/packages.d

If if the ksmeta var "$packages" has a value AND if $package_snip_dir/ 
$packages exists , use it ...

... else if $package_snip_dir/$name exists, use it ...

... else if $package_snip_dir/$profile exists, use it ...

... else, use $package_snip_dir/default.

===================================

I've tried making this work, with "#try ... #except ... #finally"  
blocks, "#if ... #elif ... #then" blocks, "os.path.isfile", and so  
on.  All of my attempts have ended in various syntax errors or  
failures that I'm at a loss to resolve.

I expect that the solution to this is simple, and I'm going to feel  
really stupid when someone points that solution out to me, but I can  
live with that.  :-)

Below is my last, best attempt, along with the error that gets  
generated.

[root ~]# cat /var/lib/cobbler/snippets/packages_select
#try
  #include raw source='/var/lib/cobbler/snippets/packages.d/' +  
$packages
#except
  #try
   #include raw source='/var/lib/cobbler/snippets/packages.d/' + $name
  #except
   #try
    #include raw source='/var/lib/cobbler/snippets/packages.d/' +  
$profile
   #except
    #try
     #include raw "/var/lib/cobbler/snippets/packages.d/DEFAULT"
    #end try
   #end try
  #end try
#end try

[root ~]# cobbler sync
sync distro: rhel4AS-x86_64
sync distro: rhel4AS-xen-x86_64
sync distro: rhel5Server-x86_64
sync distro: rhel5Server-xen-x86_64
sync profile: xen-big
Traceback (most recent call last):
   File "/usr/lib/python2.4/site-packages/cobbler/action_sync.py",  
line 373, in validate_kickstart_for_specific_profile
     self.apply_template(kfile, meta, dest)
   File "/usr/lib/python2.4/site-packages/cobbler/action_sync.py",  
line 627, in apply_template
     t = Template(source=data, searchList=[metadata])
   File "/usr/lib64/python2.4/site-packages/Cheetah/Template.py", line  
1204, in __init__
     self._compile(source, file, compilerSettings=compilerSettings)
   File "/usr/lib64/python2.4/site-packages/Cheetah/Template.py", line  
1492, in _compile
     keepRefToGeneratedCode=True)
   File "/usr/lib64/python2.4/site-packages/Cheetah/Template.py", line  
791, in compile
     raise parseError
ParseError:

Error in the Python code which Cheetah generated for this template:
= 
= 
= 
= 
= 
= 
= 
= 
========================================================================

invalid syntax  
(cheetah_DynamicallyCompiledCheetahTemplate_1207508119_67_52126.py,  
line 210)

Line|Python Code
----|-------------------------------------------------------------
208 |                    try: # generated from line 51, col 4
209 |                        self._handleCheetahInclude("/var/lib/ 
cobbler/snippets/packages.d/DEFAULT", trans=trans, includeFrom="file",  
raw=True)
210 |        write('''
            ^
211 |%post
212 |
213 |''')

= 
= 
= 
= 
= 
= 
= 
= 
========================================================================

Here is the corresponding Cheetah code.
** I had to guess the line & column numbers, so they are probably  
incorrect:

Line 61, column 1

Line|Cheetah Code
----|-------------------------------------------------------------
58  |
59  |%post
60  |
61  |$yum_config_stanza
      ^
62  |
63  |## post_select
64  |##

Error while rendering kickstart file /etc/cobbler/rhel5xen.ks to /var/ 
www/cobbler/kickstarts/xen-big/ks.cfg







More information about the et-mgmt-tools mailing list