Server IP : 85.214.239.14 / Your IP : 18.118.24.176 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/self/root/proc/2/task/2/root/lib/python3/dist-packages/ansible_test/_internal/ |
Upload File : |
"""Become abstraction for interacting with test hosts.""" from __future__ import annotations import abc import shlex from .util import ( get_subclasses, ) class Become(metaclass=abc.ABCMeta): """Base class for become implementations.""" @classmethod def name(cls) -> str: """The name of this plugin.""" return cls.__name__.lower() @property @abc.abstractmethod def method(self) -> str: """The name of the Ansible become plugin that is equivalent to this.""" @abc.abstractmethod def prepare_command(self, command: list[str]) -> list[str]: """Return the given command, if any, with privilege escalation.""" class Doas(Become): """Become using 'doas'.""" @property def method(self) -> str: """The name of the Ansible become plugin that is equivalent to this.""" raise NotImplementedError('Ansible has no built-in doas become plugin.') def prepare_command(self, command: list[str]) -> list[str]: """Return the given command, if any, with privilege escalation.""" become = ['doas', '-n'] if command: become.extend(['sh', '-c', shlex.join(command)]) else: become.extend(['-s']) return become class DoasSudo(Doas): """Become using 'doas' in ansible-test and then after bootstrapping use 'sudo' for other ansible commands.""" @classmethod def name(cls) -> str: """The name of this plugin.""" return 'doas_sudo' @property def method(self) -> str: """The name of the Ansible become plugin that is equivalent to this.""" return 'sudo' class Su(Become): """Become using 'su'.""" @property def method(self) -> str: """The name of the Ansible become plugin that is equivalent to this.""" return 'su' def prepare_command(self, command: list[str]) -> list[str]: """Return the given command, if any, with privilege escalation.""" become = ['su', '-l', 'root'] if command: become.extend(['-c', shlex.join(command)]) return become class SuSudo(Su): """Become using 'su' in ansible-test and then after bootstrapping use 'sudo' for other ansible commands.""" @classmethod def name(cls) -> str: """The name of this plugin.""" return 'su_sudo' @property def method(self) -> str: """The name of the Ansible become plugin that is equivalent to this.""" return 'sudo' class Sudo(Become): """Become using 'sudo'.""" @property def method(self) -> str: """The name of the Ansible become plugin that is equivalent to this.""" return 'sudo' def prepare_command(self, command: list[str]) -> list[str]: """Return the given command, if any, with privilege escalation.""" become = ['sudo', '-in'] if command: become.extend(['sh', '-c', shlex.join(command)]) return become SUPPORTED_BECOME_METHODS = {cls.name(): cls for cls in get_subclasses(Become)}