-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multi-file custom modules (with ModuleReplacer), outside /ansible/module... #10274
Conversation
…ule_utils/ for easy ansible core update
+1 |
the name custom_modules will confuse people, these are really module copied requirements or dependencies I would also look at plugin loader to allow for local paths, the way other plugins do, this way a module that comes with a play or role can have their extra dependencies also provided vs needing to install them in a specific ansible location. |
raise errors.AnsibleError("error importing module in %s, expecting format like 'from ansible.module_utils.basic import *'" % module_path) | ||
snippet_name = tokens[2].split()[0] | ||
snippet_names.append(snippet_name) | ||
output.write(self.slurp(os.path.join(module_custom_path, snippet_name + ".py"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this assumes that the direct import will be the only thing needed, what about dependencies of that library?
should we allow for a path or archive to copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name custom_modules will confuse people, these are really module copied requirements or dependencies
Please suggest the name of Your choice.
What about custom_lib_module?
I would also look at plugin loader to allow for local paths, the way other plugins do, this way a module that comes with a play or role can have their extra dependencies also provided vs needing to install them in a specific ansible location.
I think there is a question: how deep should we include dependences into single merged_module_file. I would suggest, that the 'standard python packages' should be installed (or manually delivered if needed) into remote host environment.
this assumes that the direct import will be the only thing needed, what about dependencies of that library?
That's true, for now it does.
I did just extend the current ansible functionality (where modules are almost self-contained).
For now, I do assume, that the required custom modules (and their dependencies) would be provided in the ANSIBLE_CUSTOM_MODULES path.
For custom_lib_module depending on another custom_lib_module:
Let's make an example: a lib file (in example: tools.py) depends on the other lib file (conf.py), then if You would import both into Your module (websrv), the ModuleReplacer would merge content of all files (websrv, tools.py, conf.py) into one, and the dependence: tools.py -> conf.py would be resolved by this phenomena.
I do assume, that the other dependencies would be just a python packages - that should be installed on the remote hosts (this can be done by other play).
should we allow for a path or archive to copy?
I'm not sure if I do understand this part of the question.
IDEA
We could also think about using the eggs.
Provided we store them in customized location on local host, we have a few ways of importing an egg into our merged_module_file.
We can:
- append eggs into merged_module_file (and loading them on_the_fly)
- sending them to the remote host before running the module, and import their content
@sirkubax can you fix the merge conflicts when you get a chance? |
I think ideally this functionality would be better implemented using plugin functionality, instead of a config. |
@sivel agreed for a basic use case. what I feel this could solve is having the equivalent of an end-user managed equivalent of |
@defionscode |
Is there any other way to implement this use currently?, I'm hitting it for a custom module I'm writting. There should be a way to include snippets from files out of module_utils dir. |
It's being worked on internally at the moment. |
I'm having the same problem. Is this feature already integrated into the core? |
Heh :) I personally use for the moment a private fork of ansible repo with this changes. For the future: |
@sirkubax discussions are all public, either here on tickets or in mailing lists (ansible-devel) or irc (#ansible-devel) currently this is waiting for the ziploader addition that we are targeting for 2.1 |
Now that Ansible 2.1 is out, is there anything blocking this from getting wrapped up? I'd love to see this pushed. |
I actually would like this to happen as well for my PR #17039. |
any update on this? I would also really like this feature |
so ziploader is already been out for 2.1 and this can be adapted to use that. |
Is this pull request solved in master branch? |
Is there any traction on this, or on using If all that's needed is a rebase / conflict resolve, I could probably do it. |
hm... @bcoca @defionscode - could you provide some summary on current project status? [BTW - I was using private fork of ansible 1.9.x , but I did recently upgrade to 2.x and the project structure has changed a lot] |
@sirkubax This PR was tested by travis-ci.org, which is no longer used. Please rebase your branch to trigger running of current tests. |
4964183
to
0a3879d
Compare
I thought @jimi-c had a WIP branch somewhere but all I can find is this: https://github.com/ansible/ansible/tree/module_utils_commmon_loading He definitely has something newer somewhere.... |
Yes, I have a different branch (which is not ready), but which supplants this one. As such, we'll close this now. Thanks! |
Is this issue fixed? |
Hi, Just place you shared code in There is a different option to use a |
Awesome! |
Yeah thanks
…On May 25, 2017 13:19, "Heungsub Lee" ***@***.***> wrote:
Awesome!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#10274 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAUkPSlIRfCuAKLMojKJoglKSZInvH3Sks5r9WPfgaJpZM4DiBsG>
.
|
Solution mentioned by @tarasmatsyk is not working to me – maybe someone can shed some light? I need to import a module called from ansible.module_utils.foo import FooClass
What am I doing wrong? ansible --version
ansible 2.3.0.0
config file = ./ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.5 (default, Aug 2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] I'm asking for help first here rather than opening up an issue because I believe I'm doing something wrong (or rather stu**d). |
Note: this is a user question. Better to take it to the mailing list or irc channel: http://docs.ansible.com/ansible/community.html#mailing-list-information action plugins (and indeed any other plugins; only modules are different) have access to all of the python libraries installed on the controller. They do not have access to the module_utils that can be bundled as plugins as they are not installed. The module_utils plugin functionality only comes into play for modules (which are bundled up with their module_util dependencies and transferred over the wire to the remote machine). For plugins, the libraries need to be installed locally on the controller instead. |
This change allows writing multi-file ansible modules (and store them outside ansible/module_utils/ directory - for easy ansible core upgrade).
The custom_modules can have external imports, that would be recognized by ModuleReplacer.
The idea is, that you can configure you custom modules directory (like other ansible vars):
EXAMPLE:
And place there Your files:
Then just include 'ansible.module_custom' in Your custom module (mine -> websrv):
and that would be merged by ModuleReplacer.
Info - in the ansible.cfg I have already 'library_path'
ansible.cfg
custom_modules = some_path/lib/modules/
library_path = some_path/lib/modules/
We could use the same variable, but it would be wise to have this configuration separated.