Using python subprocess in Kickstart snippet
I'd like to use python subprocess in my kickstart snippet.
The tail end of my /etc/cobbler/settings has:
cheetah_import_whitelist:
- "random"
- "re"
- "time"
- "subprocess"
My snippet is:
echo "#a test"
import subprocess
set $parts=subprocess.STD_INPUT_HANDLE
set $parts="XX"
echo "#$parts"
My pre-script is (Template is checked):
echo "#a-test"
$SNIPPET('spacewalk/1/a-test')
This causes a blank Kickstart File for the profile. If I comment out the set and uncomment the other set I get the Kickstart File that I expect.
Responses
Hi Tim,
Escape the '$' sign with a backslash and this should solve your problem.
The interpreter to build the kickstart from snippets breaks easily without any real indication of what is wrong.
-edit-
Also, to paste code snippets us the tilde (~) not the minus (-), the font on the 'Formatting Help' page makes it hard to distinguish :D
In Cobbler's setting for importing Python modules, there's this description:
Cheetah-language kickstart templates can import Python modules.
while this is a useful feature, it is not safe to allow them to
import anything they want. This whitelists which modules can be
imported through Cheetah. Users can expand this as needed but
should never allow modules such as subprocess or those that
allow access to the filesystem as Cheetah templates are evaluated
by cobblerd as code.
I'm assuming this is to protect the coder from themselves as they are writing snippets, i.e. the snippet could inadvertently overwrite files and execute in the dev environment if the coder isn't careful. Are there other security implications?
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
