diff options
author | James Cammarata <jimi@sngx.net> | 2017-02-14 11:17:40 -0600 |
---|---|---|
committer | James Cammarata <jimi@sngx.net> | 2017-02-14 11:23:51 -0600 |
commit | 907ee44d0a7aa6fcb5a9ff043502357b3a81ee9c (patch) | |
tree | d9440aac21e772d9e1c90b71e57176bf58dced34 | |
parent | d94b2d802e1716da77d6a6f49c89471f7d2d6b7e (diff) | |
download | ansible-perf_improvement_ini_parsing.tar.gz |
Use our custom split_args instead of shlex_splitperf_improvement_ini_parsing
Testing shows our custom splitter is MUCH quicker than shlex_split
-rw-r--r-- | lib/ansible/inventory/ini.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py index edfabb5289..8e83d9a405 100644 --- a/lib/ansible/inventory/ini.py +++ b/lib/ansible/inventory/ini.py @@ -23,14 +23,14 @@ import ast import re from ansible import constants as C -from ansible.errors import AnsibleError +from ansible.errors import AnsibleError, AnsibleParserError from ansible.inventory.host import Host from ansible.inventory.group import Group from ansible.inventory.expand_hosts import detect_range from ansible.inventory.expand_hosts import expand_hostname_range from ansible.module_utils._text import to_text from ansible.parsing.utils.addresses import parse_address -from ansible.utils.shlex import shlex_split +from ansible.parsing.splitter import split_args class InventoryParser(object): @@ -251,8 +251,17 @@ class InventoryParser(object): # gamma sudo=True user=root # to ignore comments try: - tokens = shlex_split(line, comments=True) - except ValueError as e: + tokens = split_args(line) + comment_found = False + comment_idx = None + for idx, token in enumerate(tokens): + if token == '#': + comment_found = True + comment_idx = idx + break + if comment_found: + tokens = tokens[:comment_idx] + except (ValueError, AnsibleParserError) as e: self._raise_error("Error parsing host definition '%s': %s" % (line, e)) (hostnames, port) = self._expand_hostpattern(tokens[0]) |