diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2019-03-04 15:00:49 -0500 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2019-03-04 12:00:49 -0800 |
commit | 03ceec9c78ba9eb68783d2524c8e5dc9e58008ca (patch) | |
tree | 5193c22bf002031238efaa2a89d6232c0304aebd | |
parent | 5aabb5ea026be09ddaaff6164e0233b954c3bd2c (diff) | |
download | ansible-03ceec9c78ba9eb68783d2524c8e5dc9e58008ca.tar.gz |
properly convert inputs to handle bytes/unicode (#53072) (#53124)
* 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 55dc63be3a76b31c227582c9a403133a1be492e5)
* updated as per fb
* spacer
-rw-r--r-- | changelogs/fragments/nmap_bytes_fix.yml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/inventory/nmap.py | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/changelogs/fragments/nmap_bytes_fix.yml b/changelogs/fragments/nmap_bytes_fix.yml new file mode 100644 index 0000000000..309fc1cb15 --- /dev/null +++ b/changelogs/fragments/nmap_bytes_fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - convert input into text to ensure valid comparisons in nmap inventory plugin diff --git a/lib/ansible/plugins/inventory/nmap.py b/lib/ansible/plugins/inventory/nmap.py index f9e709ee64..5b1b5375cb 100644 --- a/lib/ansible/plugins/inventory/nmap.py +++ b/lib/ansible/plugins/inventory/nmap.py @@ -57,7 +57,7 @@ from subprocess import Popen, PIPE from ansible import constants as C 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 @@ -126,7 +126,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): host = None ip = None 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) if hits: if host is not None: |