Can python classes/objects/functions be imported in puppet files(.rb files with custom providers or any other) ? Is there any way apart from "exec" to run python code using puppet?
-
You are probably better off switching to Ansible, as it is python based See http://docs.ansible.com/ansible/developing_api.html Or learning ruby and writing your add on code in ruby for puppet instead – Vorsprung Apr 14 '16 at 15:21
1 Answers
Ruby has a system()
method by which you can run an external Python program. Ruby also has fork()
and exec()
by which you can roll your own, with more control. Puppet also has wrappers around the latter that your Ruby plugin code may use.
But you seem to be asking for something different. The standard C Ruby implementation affords native (C) extensions, and Python has a C API. It is therefore possible, in principle, to embed a Python interpreter in Ruby via a native extension, with calls into it following a path Ruby --> C --> Python. You could use such an extension in any kind of Ruby plugin that Puppet supports, including custom functions, custom facts, resource providers, and even ERB templates.
In practice, I cannot recommend the embedding approach. Although I'm sure it could be made to work, it seems like a great deal of unneeded complication, with a great deal of runtime overhead.

- 160,171
- 8
- 81
- 157