* properly convert inputs to handle bytes/unicode (#53072)
* properly convert inputs to handle bytes/unicode
fixes #52186
* Update changelogs/fragments/nmap_bytes_fix.yml
Co-Authored-By: bcoca <bcoca@users.noreply.github.com>
(cherry picked from commit 55dc63be3a
)
* updated as per fb
* spacer
This commit is contained in:
parent
5aabb5ea02
commit
03ceec9c78
2 changed files with 10 additions and 2 deletions
2
changelogs/fragments/nmap_bytes_fix.yml
Normal file
2
changelogs/fragments/nmap_bytes_fix.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- convert input into text to ensure valid comparisons in nmap inventory plugin
|
|
@ -57,7 +57,7 @@ from subprocess import Popen, PIPE
|
||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.errors import AnsibleParserError
|
from ansible.errors import AnsibleParserError
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native, to_text
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||||
|
|
||||||
|
|
||||||
|
@ -126,7 +126,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
host = None
|
host = None
|
||||||
ip = None
|
ip = None
|
||||||
ports = []
|
ports = []
|
||||||
for line in stdout.splitlines():
|
|
||||||
|
try:
|
||||||
|
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
||||||
|
except UnicodeError as e:
|
||||||
|
raise AnsibleParserError('Invalid (non unicode) input returned: %s' % to_native(e))
|
||||||
|
|
||||||
|
for line in t_stdout.splitlines():
|
||||||
hits = self.find_host.match(line)
|
hits = self.find_host.match(line)
|
||||||
if hits:
|
if hits:
|
||||||
if host is not None:
|
if host is not None:
|
||||||
|
|
Loading…
Reference in a new issue