Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/become/helper.py

raw
1 # Copyright (c) 2012-2014, Michael DeHaan <[email protected]>
2 #
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 from __future__ import annotations
7
8 from ansible.plugins.loader import become_loader, get_shell_plugin
9
10
11 def call_become_plugin(task, var_options, cmd, executable=None):
12 """Helper function to call become plugin similarly on how Ansible itself handles this."""
13 plugin = become_loader.get(task["become_method"])
14 plugin.set_options(task_keys=task, var_options=var_options)
15 shell = get_shell_plugin(executable=executable)
16 return plugin.build_become_command(cmd, shell)