diff --git a/salt/modules/hosts.py b/salt/modules/hosts.py index 4a92bd5e41..bec2b1967c 100644 --- a/salt/modules/hosts.py +++ b/salt/modules/hosts.py @@ -215,9 +215,10 @@ def add_host(ip, alias): def _write_hosts(hosts): lines = [] for ip, aliases in hosts.iteritems(): - line = '{0}\t'.format(ip) - for alias in aliases: - line = '{0}\t{1}'.format(line, alias) + line = '{0}\t\t{1}'.format( + ip, + '\t\t'.join(aliases) + ) lines.append(line) hfn = __get_hosts_filename() diff --git a/tests/integration/modules/hosts.py b/tests/integration/modules/hosts.py index 39a2816f67..438c465a51 100644 --- a/tests/integration/modules/hosts.py +++ b/tests/integration/modules/hosts.py @@ -208,13 +208,8 @@ class HostsModuleTest(integration.ModuleCase): lines = salt.utils.fopen(HFN, 'r').read().splitlines() self.assertEqual(lines, [ '192.168.1.3\t\thost3.fqdn.com', - '192.168.1.1\t\thost1.fqdn.com', - '192.168.1.1\t\thost1', - '192.168.1.1\t\thost1-reorder', - '192.168.1.2\t\thost2.fqdn.com', - '192.168.1.2\t\thost2', - '192.168.1.2\t\toldhost2', - '192.168.1.2\t\thost2-reorder' + '192.168.1.1\t\thost1.fqdn.com\t\thost1\t\thost1-reorder', + '192.168.1.2\t\thost2.fqdn.com\t\thost2\t\toldhost2\t\thost2-reorder', ])