From b8799ef84e2d3f30626d2c23f5a0a2a4a6031da8 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 4 Mar 2019 14:47:38 -0500 Subject: [PATCH] improved nmap fix, updated as per fb (#53280) (cherry picked from commit 5280ae917c4a49df1bb4ff354885bc046e7ee397) --- lib/ansible/plugins/inventory/nmap.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/inventory/nmap.py b/lib/ansible/plugins/inventory/nmap.py index 72f2a140b47..5b1b5375cb2 100644 --- a/lib/ansible/plugins/inventory/nmap.py +++ b/lib/ansible/plugins/inventory/nmap.py @@ -126,8 +126,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): host = None ip = None ports = [] - for line in stdout.splitlines(): - line = to_text(line) + + 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) if hits: if host is not None: