MCPcopy Create free account
hub / github.com/saltstack/salt / call

Function call

salt/modules/ansiblegate.py:214–299  ·  view source on GitHub ↗

Call an Ansible module by invoking it. :param module: the name of the module. :param args: Arguments to pass to the module :param kwargs: keywords to pass to the module CLI Example: .. code-block:: bash salt * ansible.call ping data=foobar

(module, *args, **kwargs)

Source from the content-addressed store, hash-verified

212
213
214def call(module, *args, **kwargs):
215 """
216 Call an Ansible module by invoking it.
217
218 :param module: the name of the module.
219 :param args: Arguments to pass to the module
220 :param kwargs: keywords to pass to the module
221
222 CLI Example:
223
224 .. code-block:: bash
225
226 salt * ansible.call ping data=foobar
227 """
228
229 module_args = []
230 for arg in args:
231 module_args.append(salt.utils.json.dumps(arg))
232
233 _kwargs = {}
234 for _kw in kwargs.get("__pub_arg", []):
235 if isinstance(_kw, dict):
236 _kwargs = _kw
237 break
238 else:
239 _kwargs = {k: v for (k, v) in kwargs.items() if not k.startswith("__pub")}
240
241 for key, value in _kwargs.items():
242 module_args.append(f"{key}={salt.utils.json.dumps(value)}")
243
244 with NamedTemporaryFile(mode="w") as inventory:
245
246 ansible_binary_path = salt.utils.path.which("ansible")
247 log.debug("Calling ansible module %r", module)
248 try:
249 env = os.environ.copy()
250 env["ANSIBLE_DEPRECATION_WARNINGS"] = "0"
251
252 proc_exc = subprocess.run(
253 [
254 ansible_binary_path,
255 "localhost",
256 "--limit",
257 "127.0.0.1",
258 "-m",
259 module,
260 "-a",
261 " ".join(module_args),
262 "-i",
263 inventory.name,
264 ],
265 capture_output=True,
266 timeout=__opts__.get("ansible_timeout", DEFAULT_TIMEOUT),
267 text=True,
268 check=True,
269 shell=False,
270 env=env,
271 )

Callers 1

_cmdFunction · 0.70

Calls 9

debugMethod · 0.80
appendMethod · 0.45
dumpsMethod · 0.45
getMethod · 0.45
itemsMethod · 0.45
copyMethod · 0.45
runMethod · 0.45
loadsMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected