@@ -136,6 +136,15 @@ def __init__(
136136 Provide a custom path or sequence of path to look for ansible
137137 collections when loading/hooking the modules.
138138
139+ Ansible only initializes the module loader once, so it's not
140+ possible to have multiple `Api` instances with different
141+ values for this parameter. The first one will always be the
142+ one that matters.
143+
144+ Additionally if the loader has already been initialized prior
145+ to the creation of the Api instance, then this parameter has
146+ no effect at all.
147+
139148 Requires ansible-core >= 2.15
140149
141150 :param host_key_checking:
@@ -237,8 +246,19 @@ def __init__(
237246 collections_path = [collections_path ]
238247
239248 if Version (__version__ ) >= Version ('2.15' ):
249+ import warnings
240250 from ansible .plugins .loader import init_plugin_loader
241- init_plugin_loader (collections_path )
251+ # NOTE: Ansible emits a warning here, but it's harmless to
252+ # call this function multiple times, it just doesn't
253+ # do anything the second time around.
254+ # We don't want to propagate this warning.
255+ with warnings .catch_warnings ():
256+ warnings .filterwarnings (
257+ 'ignore' ,
258+ r'AnsibleCollectionFinder has already been configured' ,
259+ UserWarning
260+ )
261+ init_plugin_loader (collections_path )
242262
243263 for module in list_ansible_modules ():
244264 ModuleRunner (module ).hookup (self )
0 commit comments