Repository: ansible/ansible

Issue:
host pattern that is an integer produces traceback
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
Inventory

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->

2.3 -> devel
```

```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->

##### SUMMARY
<!--- Explain the problem briefly -->

This came up on slack a bit ago, I suspect an issue was not logged. It looks to me as inventory is interpreting the group as an integer, then failing when it is not iterable. 

The issue seems to comes from https://github.com/ansible/ansible/blob/2ffe3c42bb15263ad67dd36842712d9d3ec99070/lib/ansible/inventory/manager.py#L94


##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
Create a group in inventory with only integers
<!--- Paste example playbooks or commands between quotes below -->
```yaml
[2911]
ios-rt01
ios-rt02
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
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
```





Discussion:
cc @dagnello @emonty @j2sol @juliakreger @rcarrillocruz @shrews @thingee
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
no, `pattern` does not come from inventory, it comes from host patterns

Resolving patch:
diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py
--- a/lib/ansible/inventory/manager.py
+++ b/lib/ansible/inventory/manager.py
@@ -87,11 +87,12 @@ def split_host_pattern(pattern):
 
     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.
-
-    elif ',' in pattern:
+    if ',' in pattern:
         patterns = re.split('\s*,\s*', pattern)
 
     # If it doesn't, it could still be a single pattern. This accounts for


Test patch: