Issue 1:
Hello. For some particularly purposes I'm using restricted user for getting access to the servers by ssh. This user has «no-pty» option in ssh authorized key and when I run task through ansible without «sudo: yes» option it runs great. But sudoable commands is crashed with this traceback:

GATHERING FACTS ***************************************************************
fatal: [alma.relax.ru] => Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 364, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 443, in _executor_internal
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 597, in _executor_internal_inner
result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
File "/usr/lib/python2.6/site-packages/ansible/runner/action_plugins/normal.py", line 54, in run
return self.runner._execute_module(conn, tmp, module_name, module_args, inject=inject, complex_args=complex_args)
File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 333, in _execute_module
res = self._low_level_exec_command(conn, cmd, tmp, sudoable=True)
File "/usr/lib/python2.6/site-packages/ansible/runner/__init__.py", line 637, in _low_level_exec_command
rc, stdin, stdout, stderr = conn.exec_command(cmd, tmp, sudo_user, sudoable=sudoable, executable=executable)
File "/usr/lib/python2.6/site-packages/ansible/runner/connection_plugins/paramiko_ssh.py", line 203, in exec_command
height=int(os.getenv('LINES', 0)))
File "/usr/lib/python2.6/site-packages/paramiko/channel.py", line 158, in get_pty
self._wait_for_event()
File "/usr/lib/python2.6/site-packages/paramiko/channel.py", line 1084, in _wait_for_event
raise e
SSHException: Channel closed.

I've scoured ansible source code and found paramiko function get_pty() call in the paramiko_ssh.py file with shady comment «sudo usually requires a PTY» and without any checks if that is really necessary. I have disabled following option in my sudoers: #Defaults requiretty and I really don't need that.

I've just comment out this function call and, in the first glance, all starts work seamless. After that, I read discussion in #1801 and it shed some light about problem. I've been using fabric with option sudo.pty = False in my configuration on CentOS and FreeBSD for two years without any problems. I think some additional option pty: no following with sudo: yes would be great.

I don't familiar with ansible internal architecture so I haven't written a patch by myself yet.

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

files/replace module

ANSIBLE VERSION

2.4.0.0

CONFIGURATION

N/A

OS / ENVIRONMENT

N/A

SUMMARY

when using before/after to select text to apply the replace to, replace still acts on whole file

STEPS TO REPRODUCE

Look at the code, eg try before/after patterns that exist in file which regexp that appears outside the intended text selection area :-)

ansible/modules/files/replace.py:

if result[1] > 0 and section != result[0]:
if pattern:
result = (contents.replace(section, result[0]), result[1])

Should be "section.replace" rather than "contents.replace"