Ansible Social

262 Members
A place for the Ansible Community to welcome new people, chat about general Ansible Topics, and signpost users to other suitable rooms when needed. Feel free to report your Ansible news here - just mention @newsbot or add a :o: to your post! Bridged to #ansible-social on Libera - if joining from Libera, please be aware the channel is logged on Matrix 15 Servers

Load older messages

7 Jul 2022
In reply to @briantist:libera.chat
weiyentan: sure; this also may not be the best method for your use case
Oh. In my use case I think I will follow bcoca way through the task . But I have learnt how to write windows ansible libraries using powershell , I want to extend it to write plugins and libraries in python. Particularly action plugins because i can see value in that
@briantist:libera.chatbriantist yes, definitely follow bcoca's advice and avoid writing an action if you don't need to! 16:59:06
@weiyentan:matrix.orgweiyentan What about this use case. Let's say i want to create reporting (let's say in excel or word. I could use the module setup or other 'facts' type module. Then In the action plugin I could use the docx or excel python modules to create the report with? 17:03:57
@briantist:libera.chatbriantist I'm not sure I have enough information to say... generally just remember that a module execution always has two portions: the controller side (action) and the remote side (the module). If you don't provide an action, a default is used (`normal.py`, or `async.py`, or whatever, I'm probably messing this part up a bit). The action is good when you need to run part of all of your task on the controller, or more finely control 17:11:39
@briantist:libera.chatbriantist how/when the remote module portion is executed, or when you need to coordinate the execution of multiple remote modules and maybe make some coherent set of results out of them. The `template` "module" is a good example, where the templating happens on the controller, and the `copy` (I think?) module is used to for putting the result in place (oversimplification...) 17:11:39
@weiyentan:matrix.orgweiyentan The second part is the use case I am referring to 17:13:05
@weiyentan:matrix.orgweiyentan Need to get 'facts' of multiple nodes then i want to get those facts and generate a report out of it 17:13:44
@briantist:libera.chatbriantistthe multiple nodes part sounds suspect; ansible is running each task against a specific host17:17:15
@briantist:libera.chatbriantist I don't recommend trying to muck with that in an action (or otherwise) 17:17:30
@weiyentan:matrix.orgweiyentan Yeah I would need to because I would need to get a task for each host 17:22:22
@weiyentan:matrix.orgweiyentan Or fact... 17:22:42
@weiyentan:matrix.orgweiyentan But I see where you are going 17:22:49
@weiyentan:matrix.orgweiyentan The module that would be run on the host is the just setup or another fact. But the documentation part would run as a plugin? As everything is collated on the controller 17:25:33
@briantist:libera.chatbriantist to me it sounds like you'd be better off running `gather_facts` on each host as usual, and then maybe doing a `run_once` task or a new play that accesses the variables from the other hosts to build a report one time. That report creation could be a custom module, but wouldn't need any action plugin as long as you could count on the invoker to pass in all the things needed. 17:25:53
@briantist:libera.chatbriantistI suppose an action plugin could internalize the gathering of all those vars from the controller side, and then it could do all the work on the controller too, or pass them to a module (which at that could run local or remote)17:26:39
@briantist:libera.chatbriantistnot sure how good of an idea that is though17:26:45
@weiyentan:matrix.orgweiyentan If it was done as a run_once. Would the host be localhost? 17:28:18
@briantist:libera.chatbriantistno, it would be the first host that Ansible would have executed on17:28:43
@briantist:libera.chatbriantistso it may not be predictable17:28:49
@briantist:libera.chatbriantistbut you could `delegate_to: localhost` to do that17:29:00
@weiyentan:matrix.orgweiyentan But then if it is delegate to localhost isn't that what a plugin is for? 17:29:30
@briantist:libera.chatbriantist not exactly, no, the module is still executed in a fork (so not in the controller), it's just that the host happens to be the same host where you're running ansible 17:30:04
@briantist:libera.chatbriantistand it uses the `local` connection17:30:14
@weiyentan:matrix.orgweiyentan Well. In the use case I have. I have the dates gathered from the remote hosts. The report is generated on the controller 17:31:15
@weiyentan:matrix.orgweiyentan * (null) 17:31:27
@weiyentan:matrix.orgweiyentan I thought it is nice to have ansible be the controller in situations like this where it is the central point 17:33:03
@briantist:libera.chatbriantist I'm just saying, a module can be executed on a remote host or on the controller (on, not IN, so not in the same context as a plugin). A plugin on the other hand has access to a lot more "stuff" (often stuff you shouldn't really be accessing), but its code doesn't execute remotely. It can be a lot easier to reason about modules, since they simply take inputs and produce results, and that can keep you out of trouble 17:33:48
@briantist:libera.chatbriantistmost of the time, executing ON the controller, and not in the controller process, is good enough17:34:05
@briantist:libera.chatbriantist for your report generation, I'd wager that is true in this case too 17:34:23

I saw the example on the action plugin and example the executemodule method. It had the example of facts and generating something back. I really liked that notion because the information came back as a dict which I can then process.

How would that work similarly if it was done as a module Running on the controller instead of the process as you say? Because I feel the workflow will be different


There are no newer messages yet.

Back to Room List