# Buggy code
def _expand_target(self):
    """
    Figures out if the target is a reachable host without wildcards, expands if any.
    :return:
    """
    # TODO: Support -L
    target = self.opts["tgt"]
    if isinstance(target, list):
        return

    hostname = self.opts["tgt"].split("@")[-1]
    needs_expansion = "*" not in hostname and salt.utils.network.is_reachable_host(
        hostname
    )
    if needs_expansion:
        hostname = salt.utils.network.ip_to_host(hostname)
        self._get_roster()
        for roster_filename in self.__parsed_rosters:
            roster_data = self.__parsed_rosters[roster_filename]
            if not isinstance(roster_data, bool):
                for host_id in roster_data:
                    if hostname in [host_id, roster_data.get("host")]:
                        if hostname != self.opts["tgt"]:
                            self.opts["tgt"] = hostname
                        self.__parsed_rosters[self.ROSTER_UPDATE_FLAG] = False
                        return


# Traceback (AssertionError)
salt:/srv # salt-ssh minionname state.sls deploy.system+root......
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
AssertionError:
Traceback (most recent call last):
File "/usr/bin/salt-ssh", line 11, in <module>
sys.exit(salt_ssh())
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 425, in salt_ssh
client.run()
File "/usr/lib/python2.7/site-packages/salt/cli/ssh.py", line 23, in run
ssh = salt.client.ssh.SSH(self.config)
File "/usr/lib/python2.7/site-packages/salt/client/ssh/__init__.py", line 235, in __init__
self.tgt_type)
File "/usr/lib/python2.7/site-packages/salt/roster/__init__.py", line 105, in targets
targets.update(self.rosters[f_str](tgt, tgt_type))
File "/usr/lib/python2.7/site-packages/salt/roster/flat.py", line 49, in targets
rmatcher = RosterMatcher(conditioned_raw, tgt, tgt_type, 'ipv4')
File "/usr/lib/python2.7/site-packages/salt/roster/flat.py", line 58, in __init__
assert tgt
AssertionError
Traceback (most recent call last):
File "/usr/bin/salt-ssh", line 11, in <module>
sys.exit(salt_ssh())
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 425, in salt_ssh
client.run()
File "/usr/lib/python2.7/site-packages/salt/cli/ssh.py", line 23, in run
ssh = salt.client.ssh.SSH(self.config)
File "/usr/lib/python2.7/site-packages/salt/client/ssh/__init__.py", line 235, in __init__
self.tgt_type)
File "/usr/lib/python2.7/site-packages/salt/roster/__init__.py", line 105, in targets
targets.update(self.rosters[f_str](tgt, tgt_type))
File "/usr/lib/python2.7/site-packages/salt/roster/flat.py", line 49, in targets
rmatcher = RosterMatcher(conditioned_raw, tgt, tgt_type, 'ipv4')
File "/usr/lib/python2.7/site-packages/salt/roster/flat.py", line 58, in __init__
assert tgt
AssertionError

# Fixed code
def _expand_target(self):
    """
    Figures out if the target is a reachable host without wildcards, expands if any.
    :return:
    """
    # TODO: Support -L
    target = self.opts["tgt"]
    if isinstance(target, list):
        return

    hostname = self.opts["tgt"].split("@")[-1]
    needs_expansion = "*" not in hostname and salt.utils.network.is_reachable_host(
        hostname
    )
    if needs_expansion:
        hostname = salt.utils.network.ip_to_host(hostname)
        if hostname is None:
            # Reverse lookup failed
            return
        self._get_roster()
        for roster_filename in self.__parsed_rosters:
            roster_data = self.__parsed_rosters[roster_filename]
            if not isinstance(roster_data, bool):
                for host_id in roster_data:
                    if hostname in [host_id, roster_data.get("host")]:
                        if hostname != self.opts["tgt"]:
                            self.opts["tgt"] = hostname
                        self.__parsed_rosters[self.ROSTER_UPDATE_FLAG] = False
                        return