-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Got Ansible own modules? Run them from within the Salt just like that! #43504
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
Conversation
|
@meaksh @dincamihai @cachedout — guys, Merry Christmas. 😉 Keep an eye on it (ignore lints and little bits, let it boil, I will look after a while). |
4239191 to
43b0c48
Compare
|
re-run lint |
|
This is awesome! My main concern here is the departure from the How do you feel about that, @isbm ? |
|
@cachedout I feel not very well about. 😉 We actually thought about that and expected this concern, still chose to depart from that for these reasons: ...rather then 😆 On the other hand, why not depart anyway? Modules in Salt are Alas, when the entire community will still start cry "Nah, no, we do not want stick to the Salt spirit and do |
43b0c48 to
d6c4944
Compare
|
Personally I do not like the departing from the module.function model. We already have other similar things that work with the whatever.call model. Between the salt module https://docs.saltstack.com/en/latest/ref/runners/all/salt.runners.salt.html#salt.runners.salt.cmd And the way that most proxy minions are written. https://github.com/saltstack/salt/blob/2017.7/salt/modules/esxi.py#L52 We already have this kind of behavior in place. My 2¢, Thanks. Daniel |
|
@gtmanfred It is not a runner module, and the paradigm is different. When an Ansible module is called, it is called like being a part of Salt (this is a migration feature, not just generic execution implementation), while in your examples parameters are passed to somewhere else towards generic function target. And even your example isn't the best one as it would be better to incorporate there the model I propose. Alongside of the weird path And yes, unfortunately we have |
|
@thatch45 thoughts? |
|
@s0undt3ch do you have any ideas why tests on Ubuntu 16 fails that way? I am trying with PyTest and "traditional" tests in different directions and they are passing... This is what happens on the Ubuntu 16: Different exception content?.. Maybe it will go away if I try now to see if the exception is raised at all. But this will kind of make the test a bit "dull" (too generic). Still I don't know how this env will react, since I am "poking the sky", in a hope it won't fail. |
|
Go Go Jenkins! |
salt/modules/ansiblegate.py
Outdated
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.
What do you think about using salt.utils.timed_subprocess here and in the line below so that we can bail out if we hang?
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.
Good point. Let me check for it. Getting back here ASAP.
salt/modules/ansiblegate.py
Outdated
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.
A more descriptive function name here would help make this more maintainable in the future. :]
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.
OK
6a1fd40 to
1de723b
Compare
|
@cachedout OK, this now should be good enough. |
|
@cachedout I've also added an option |
|
@cachedout anything else I need to do here? |
57f4ad1 to
59261b6
Compare
|
@cachedout @thatch45 is there any chances to get this done? It is blocking further development of e.g. conversion Ansible playbooks to SLS. 😢 ... |
59261b6 to
8873a92
Compare
What does this PR do?
In case you want to migrate away from Ansible, but have already modules written for it — no worries. Just toss them in and run them from Salt and Salt states.
Limitations
Currently, only Python-written modules are supported. Support for other languages are still in progress.
Requirements
The entire Ansible should be installed on the Minion. No remote execution at the moment. Continuation of this work can pull required files from the Ansible through the Salt transport. These files should be installed on Master only (in a future) and then thus get executed on the Minions.
Description and Usage
Normally Salt modules are usually
module.function. That is, a typical call of a function from the module will be:salt hostname module.function some=parameters. But since we are connecting the entire Ansible world to the Salt universe, we would like to keep the namespace as this is inside the Ansible. That said, any Ansible module is placed in the sub-directory that potentially can clash with other same-named module. Regardless the future plans of Ansible community, we already have a namespace introduced. Therefore any Ansible module is called with a full "path", prefixed withansible:If you use typical development environment, this will result to the following:
Listing available Ansible modules
In order to list all available Ansible modules, call
ansible.list:To filter them out, just type a string that matches inside them, e.g. "linux":
Getting more information about the module
You can read all the details about any Ansible modules by issuing
ansible.help. For example:At this point you may ask for
short_description,notesetc. For example, to know how to use it, calloptions:Calling Ansible modules
Calling Ansible modules are just like any other Salt modules, straight-forward, except they will be needing to stay within their own namespace, which is different than we are using typically in Salt:
Calling from the SLS files
That is also supported. Naturally, you can use typical
module.runif you like, but you've also got a dedicated Ansible state module. The syntax/example is the same as for new syntax formodule.run. It also supports a "batch mode", or "Ansible playbook mode" where tasks can be executed from within one SLS file:For example, this state will fail, because
foo.barmodule does not exist, as well asnetwork.junos.junos_packagerequires some parameters. However it will still call everything one after another:This results to the following output:
Tests written?
Yes
Please review Salt's Contributing Guide for best practices.