Reputation: 817
I have a custom Ansible module written that will query my cmdb for host details. Next I need to call the builtin add_host
module to iterate over those results and update the Ansible inventory.
Could someone please show a simple example of how to call the builtin module add_host
from a custom Ansible module? I have looked around online and can't find any documents that describe specifically this.
When I look at the builin add_host
stuff, it appears the module is just being used for the DOC section and as a pointer to the plugin. Looking at the plugin, I'm not sure how I could import/call that remotely.
These are the two files I have on my machine for add_host
:
Thank you!
Upvotes: 0
Views: 740
Reputation: 29
add_host is implemented as an action plugin. Ansible engine will check if an action plugin exists with the same name as a task (add_host) if yes it will invoke that action plugin if not it will try to search for module file name corresponding to the task name. This is generally done for modules that execute on the control node itself.
Here’s an example of calling one module from another https://github.com/ansible-collections/community.yang/blob/main/plugins/action/get.py#L123. In this case the community.yang.get module (action plugin) internally invokes ansible.netcommon.netconf_get module
Upvotes: 1