# Buggy code
def split_host_pattern(pattern):
    """
    Takes a string containing host patterns separated by commas (or a list
    thereof) and returns a list of single patterns (which may not contain
    commas). Whitespace is ignored.

    Also accepts ':' as a separator for backwards compatibility, but it is
    not recommended due to the conflict with IPv6 addresses and host ranges.

    Example: 'a,b[1], c[2:3] , d' -> ['a', 'b[1]', 'c[2:3]', 'd']
    """

    if isinstance(pattern, list):
        return list(itertools.chain(*map(split_host_pattern, pattern)))

    # If it's got commas in it, we'll treat it as a straightforward
    # comma-separated list of patterns.

    elif "," in pattern:
        patterns = re.split("\s*,\s*", pattern)

    # If it doesn't, it could still be a single pattern. This accounts for
    # non-separator uses of colons: IPv6 addresses and [x:y] host ranges.
    else:
        try:
            (base, port) = parse_address(pattern, allow_ranges=True)
            patterns = [pattern]
        except:
            # The only other case we accept is a ':'-separated list of patterns.
            # This mishandles IPv6 addresses, and is retained only for backwards
            # compatibility.
            patterns = re.findall(
                r"""(?:             # We want to match something comprising:
                        [^\s:\[\]]  # (anything other than whitespace or ':[]'
                        |           # ...or...
                        \[[^\]]*\]  # a single complete bracketed expression)
                    )+              # occurring once or more
                """,
                pattern,
                re.X,
            )

    return [p.strip() for p in patterns]


# Traceback (TypeError)
Using /etc/ansible/ansible.cfg as config file
PLAYBOOK: ios_radius_2.yml ************************************************************************************************************************
1 plays in ios_radius_2.yml
ERROR! Unexpected Exception: argument of type 'int' is not iterable
the full traceback was:
Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 109, in <module>
exit_code = cli.run()
File "/usr/lib/python2.7/dist-packages/ansible/cli/playbook.py", line 154, in run
results = pbex.run()
File "/usr/lib/python2.7/dist-packages/ansible/executor/playbook_executor.py", line 125, in run
all_vars = self._variable_manager.get_vars(loader=self._loader, play=play)
File "/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py", line 236, in get_vars
include_delegate_to=include_delegate_to,
File "/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py", line 429, in _get_magic_variables
variables['ansible_play_hosts_all'] = [x.name for x in self._inventory.get_hosts(pattern=pattern, ignore_restrictions=True)]
File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 247, in get_hosts
patterns = Inventory.split_host_pattern(pattern)
File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 284, in split_host_pattern
elif ',' in pattern:
TypeError: argument of type 'int' is not iterable
Add Comment

# Fixed code
def split_host_pattern(pattern):
    """
    Takes a string containing host patterns separated by commas (or a list
    thereof) and returns a list of single patterns (which may not contain
    commas). Whitespace is ignored.

    Also accepts ':' as a separator for backwards compatibility, but it is
    not recommended due to the conflict with IPv6 addresses and host ranges.

    Example: 'a,b[1], c[2:3] , d' -> ['a', 'b[1]', 'c[2:3]', 'd']
    """

    if isinstance(pattern, list):
        return list(itertools.chain(*map(split_host_pattern, pattern)))
    elif not isinstance(pattern, string_types):
        pattern = to_native(pattern)

    # If it's got commas in it, we'll treat it as a straightforward
    # comma-separated list of patterns.
    if "," in pattern:
        patterns = re.split("\s*,\s*", pattern)

    # If it doesn't, it could still be a single pattern. This accounts for
    # non-separator uses of colons: IPv6 addresses and [x:y] host ranges.
    else:
        try:
            (base, port) = parse_address(pattern, allow_ranges=True)
            patterns = [pattern]
        except:
            # The only other case we accept is a ':'-separated list of patterns.
            # This mishandles IPv6 addresses, and is retained only for backwards
            # compatibility.
            patterns = re.findall(
                r"""(?:             # We want to match something comprising:
                        [^\s:\[\]]  # (anything other than whitespace or ':[]'
                        |           # ...or...
                        \[[^\]]*\]  # a single complete bracketed expression)
                    )+              # occurring once or more
                """,
                pattern,
                re.X,
            )

    return [p.strip() for p in patterns]