def __init__(self, play_context, new_stdin, *args, **kwargs): # All these hasattrs allow subclasses to override these parameters if not hasattr(self, '_play_context'): self._play_context = play_context if not hasattr(self, '_new_stdin'): self._new_stdin = new_stdin # Backwards compat: self._display isn't really needed, just import the global display and use that. if not hasattr(self, '_display'): self._display = display if not hasattr(self, '_connected'): self._connected = False self.success_key = None self.prompt = None self._connected = False # load the shell plugin for this action/connection if play_context.shell: shell_type = play_context.shell elif hasattr(self, '_shell_type'): shell_type = getattr(self, '_shell_type') else: shell_type = 'sh' shell_filename = os.path.basename(self._play_context.executable) for shell in shell_loader.all(): if shell_filename in shell.COMPATIBLE_SHELLS: shell_type = shell.SHELL_FAMILY break self._shell = shell_loader.get(shell_type) if not self._shell: raise AnsibleError("Invalid shell type specified (%s), or the plugin for that shell type is missing." % shell_type)
def test_sudo(mocker, parser, reset_cli_args): options = parser.parse_args([]) context._init_global_context(options) sudo = become_loader.get('sudo') sh = shell_loader.get('sh') sh.executable = "/bin/bash" sudo.set_options(direct={ 'become_user': '******', 'become_flags': '-n -s -H', }) cmd = sudo.build_become_command('/bin/foo', sh) assert re.match( r"""sudo\s+-n -s -H\s+-u foo /bin/bash -c 'echo BECOME-SUCCESS-.+? ; /bin/foo'""", cmd), cmd sudo.set_options( direct={ 'become_user': '******', 'become_flags': '-n -s -H', 'become_pass': '******', }) cmd = sudo.build_become_command('/bin/foo', sh) assert re.match( r"""sudo\s+-s\s-H\s+-p "\[sudo via ansible, key=.+?\] password:"******""", cmd), cmd
def __init__(self, play_context, new_stdin, *args, **kwargs): super(ConnectionBase, self).__init__() # All these hasattrs allow subclasses to override these parameters if not hasattr(self, '_play_context'): self._play_context = play_context if not hasattr(self, '_new_stdin'): self._new_stdin = new_stdin # Backwards compat: self._display isn't really needed, just import the global display and use that. if not hasattr(self, '_display'): self._display = display if not hasattr(self, '_connected'): self._connected = False self.success_key = None self.prompt = None self._connected = False # load the shell plugin for this action/connection if play_context.shell: shell_type = play_context.shell elif hasattr(self, '_shell_type'): shell_type = getattr(self, '_shell_type') else: shell_type = 'sh' shell_filename = os.path.basename(self._play_context.executable) for shell in shell_loader.all(): if shell_filename in shell.COMPATIBLE_SHELLS: shell_type = shell.SHELL_FAMILY break self._shell = shell_loader.get(shell_type) if not self._shell: raise AnsibleError("Invalid shell type specified (%s), or the plugin for that shell type is missing." % shell_type)
def test_su(mocker, parser, reset_cli_args): options = parser.parse_args([]) context._init_global_context(options) su = become_loader.get('su') sh = shell_loader.get('sh') sh.executable = "/bin/bash" su.set_options(direct={ 'become_user': '******', 'become_flags': '', }) cmd = su.build_become_command('/bin/foo', sh) assert re.match( r"""su\s+foo -c '/bin/bash -c '"'"'echo BECOME-SUCCESS-.+?; /bin/foo'"'"''""", cmd)