Repository: ansible/ansible

Issue:
add_host does not recognise `host` alias.
##### ISSUE TYPE
 - Documentation Report

##### COMPONENT NAME
add_host

##### ANSIBLE VERSION
```
ansible 2.3.1.0
  config file = /path/to/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jan 03 2017, 17:41:54) [GCC]
```
##### SUMMARY
Documentation says parameter `name` has two alias named `hostname` and `host`.
However,add_host does not recognise `host`.
In fact, current implementaion for add_host does not check the `host` parameter: 
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/add_host.py#L49

##### STEPS TO REPRODUCE
```yaml
- name: Add the server to inventory.
  add_host:
    host: 192.168.10.1
    groups: server
```

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
creating host via 'add_host': hostname=None
ERROR! Unexpected Exception: unsupported operand type(s) for +: 'NoneType' and 'str'
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/site-packages/ansible/cli/playbook.py", line 154, in run
    results = pbex.run()
  File "/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 153, in run
    result = self._tqm.run(play=play)
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 284, in run
    play_return = strategy.run(iterator, play_context)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/strategy/linear.py", line 278, in run
    results += self._wait_on_pending_results(iterator)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 574, in _wait_on_pending_results
    results = self._process_pending_results(iterator)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 483, in _process_pending_results
    self._add_host(new_host_info, iterator)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 595, in _add_host
    self._inventory.get_host_vars(new_host)
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 791, in get_host_vars
    return self._get_hostgroup_vars(host=host, group=None, new_pb_basedir=new_pb_basedir, return_results=return_results)
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 862, in _get_hostgroup_vars
    elif group is None and any(map(lambda ext: host.name + ext in self._host_vars_files, C.YAML_FILENAME_EXTENSIONS)):
  File "/usr/lib/python2.7/site-packages/ansible/inventory/__init__.py", line 862, in <lambda>
    elif group is None and any(map(lambda ext: host.name + ext in self._host_vars_files, C.YAML_FILENAME_EXTENSIONS)):
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
```


Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/inventory/add_host.py b/lib/ansible/modules/inventory/add_host.py
--- a/lib/ansible/modules/inventory/add_host.py
+++ b/lib/ansible/modules/inventory/add_host.py
@@ -44,6 +44,7 @@
     - This module bypasses the play host loop and only runs once for all the hosts in the play, if you need it
       to iterate use a with\_ directive.
     - This module is also supported for Windows targets.
+    - The alias 'host' of the parameter 'name' is only available on >=2.4
 author:
     - "Ansible Core Team"
     - "Seth Vidal"
diff --git a/lib/ansible/plugins/action/add_host.py b/lib/ansible/plugins/action/add_host.py
--- a/lib/ansible/plugins/action/add_host.py
+++ b/lib/ansible/plugins/action/add_host.py
@@ -46,7 +46,7 @@ def run(self, tmp=None, task_vars=None):
         result = super(ActionModule, self).run(tmp, task_vars)
 
         # Parse out any hostname:port patterns
-        new_name = self._task.args.get('name', self._task.args.get('hostname', None))
+        new_name = self._task.args.get('name', self._task.args.get('hostname', self._task.args.get('host', None)))
         display.vv("creating host via 'add_host': hostname=%s" % new_name)
 
         try:


Test patch: