Hello,
I did a small experiment with turning the ansible "library" modules
into python modules that can be imported and used from normal python
code and wanted to see what other people think. Here is a demo of what
it does:
https://github.com/lost-theory/ansible/blob/module_experiment/demo.py#L35
The changes are in this branch:
https://github.com/lost-theory/ansible/commits/module_experiment
My reason for doing this is that I think the code inside the modules
is very useful, and it would be nice to import, extend, run, etc. from
other python code. Right now they are sort of locked into running from
the command line in a specialized way (INCLUDE_ANSIBLE_MODULE_COMMON,
hardcoding arguments into MODULE_ARGS, etc.). There was a mailing list
post from a few days ago where some folks were asking for something
similar:
https://groups.google.com/forum/?fromgroups=#!topic/ansible-project/7SByPqJxa7Q
Some examples of things that would make this easier and would not
disrupt the "language agnostic" goal too much:
1. move the "main()" call that is currently at the bottom of every
module into an "if __name__ == '__main__'" block.
2. use return values and exceptions instead of calling exit_json or
sys.exit directly
3. import module_common.py instead of writing its contents into each module
4. allow for arguments to be passed into a module in a programmable
way instead of the hardcoded MODULE_ARGS "constant"
Would patches be accepted for those kinds of changes? Or is there a
better way to do this kind of thing?
thanks,
Steve