# Buggy code
def run(self, tmp=None, task_vars=None):
    if task_vars is None:
        task_vars = dict()

    result = super(ActionModule, self).run(tmp, task_vars)

    if self._play_context.check_mode:
        result["skipped"] = True
        result["msg"] = "check mode not supported for this module"
        return result

    # Parse out any hostname:port patterns
    new_name = self._task.args.get("name", self._task.args.get("hostname", None))
    display.vv("creating host via 'add_host': hostname=%s" % new_name)

    name, port = parse_address(new_name, allow_ranges=False)
    if not name:
        raise AnsibleError("Invalid inventory hostname: %s" % new_name)
    if port:
        self._task.args["ansible_ssh_port"] = port

    groups = self._task.args.get(
        "groupname", self._task.args.get("groups", self._task.args.get("group", ""))
    )
    # add it to the group if that was specified
    new_groups = []
    if groups:
        for group_name in groups.split(","):
            if group_name not in new_groups:
                new_groups.append(group_name.strip())

    # Add any variables to the new_host
    host_vars = dict()
    special_args = frozenset(("name", "hostname", "groupname", "groups"))
    for k in self._task.args.keys():
        if k not in special_args:
            host_vars[k] = self._task.args[k]

    result["changed"] = True
    result["add_host"] = dict(host_name=name, groups=new_groups, host_vars=host_vars)
    return result


# Traceback (AttributeError)
$ ansible -vvv all -c guestfs -i 'Fedora-Cloud-Atomic-23-20151215.x86_64.qcow2:/dev/sda1,'  -m ping
Using /home/misc/.ansible.cfg as config file
Unexpected Exception: 'NoneType' object has no attribute 'split'
the full traceback was:

Traceback (most recent call last):
File "/home/misc/checkout/git/ansible/bin/ansible", line 85, in <module>
sys.exit(cli.run())
File "/home/misc/checkout/git/ansible/lib/ansible/cli/adhoc.py", line 187, in run
result = self._tqm.run(play)
File "/home/misc/checkout/git/ansible/lib/ansible/executor/task_queue_manager.py", line 237, in run
play_return = strategy.run(iterator, play_context)
File "/home/misc/checkout/git/ansible/lib/ansible/plugins/strategy/linear.py", line 217, in run
task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=task)
File "/home/misc/checkout/git/ansible/lib/ansible/vars/__init__.py", line 245, in get_vars
all_vars = combine_vars(all_vars, host.get_vars())
File "/home/misc/checkout/git/ansible/lib/ansible/inventory/host.py", line 129, in get_vars
results['inventory_hostname_short'] = self.name.split('.')[0]
AttributeError: 'NoneType' object has no attribute 'split'

# Fixed code
def run(self, tmp=None, task_vars=None):
    if task_vars is None:
        task_vars = dict()

    result = super(ActionModule, self).run(tmp, task_vars)

    if self._play_context.check_mode:
        result["skipped"] = True
        result["msg"] = "check mode not supported for this module"
        return result

    # Parse out any hostname:port patterns
    new_name = self._task.args.get("name", self._task.args.get("hostname", None))
    display.vv("creating host via 'add_host': hostname=%s" % new_name)

    try:
        name, port = parse_address(new_name, allow_ranges=False)
    except:
        # not a parsable hostname, but might still be usable
        name = new_name
        port = None

    if port:
        self._task.args["ansible_ssh_port"] = port

    groups = self._task.args.get(
        "groupname", self._task.args.get("groups", self._task.args.get("group", ""))
    )
    # add it to the group if that was specified
    new_groups = []
    if groups:
        for group_name in groups.split(","):
            if group_name not in new_groups:
                new_groups.append(group_name.strip())

    # Add any variables to the new_host
    host_vars = dict()
    special_args = frozenset(("name", "hostname", "groupname", "groups"))
    for k in self._task.args.keys():
        if k not in special_args:
            host_vars[k] = self._task.args[k]

    result["changed"] = True
    result["add_host"] = dict(host_name=name, groups=new_groups, host_vars=host_vars)
    return result