Merge pull request #5337 from bob-smith/bugfixFQDNParsing

Fix inventory parsing so that FQDN can be parsed without throwing ssh port error
pull/5471/merge
jctanner 11 years ago
commit 59d99c17b3

@ -89,10 +89,10 @@ class InventoryParser(object):
# 0. A hostname that contains a range pesudo-code and a port
# 1. A hostname that contains just a port
if hostname.count(":") > 1:
# probably an IPv6 addresss, so check for the format
# XXX:XXX::XXX.port, otherwise we'll just assume no
# port is set
if hostname.find(".") != -1:
# Possible an IPv6 address, or maybe a host line with multiple ranges
# IPv6 with Port XXX:XXX::XXX.port
# FQDN foo.example.com
if hostname.count(".") == 1:
(hostname, port) = hostname.rsplit(".", 1)
elif (hostname.find("[") != -1 and
hostname.find("]") != -1 and

@ -163,6 +163,21 @@ class TestInventory(unittest.TestCase):
var = inventory.get_variables('FE80:EF45::12:1')
self.assertEqual(var['ansible_ssh_port'], 2222)
def test_simple_string_fqdn(self):
inventory = Inventory('foo.example.com,bar.example.com')
hosts = inventory.list_hosts()
self.assertEqual(sorted(hosts), sorted(['foo.example.com','bar.example.com']))
def test_simple_string_fqdn_port(self):
inventory = Inventory('foo.example.com:2222,bar.example.com')
hosts = inventory.list_hosts()
self.assertEqual(sorted(hosts), sorted(['foo.example.com','bar.example.com']))
def test_simple_string_fqdn_vars(self):
inventory = Inventory('foo.example.com:2222,bar.example.com')
var = inventory.get_variables('foo.example.com')
self.assertEqual(var['ansible_ssh_port'], 2222)
def test_simple_vars(self):
inventory = self.simple_inventory()
vars = inventory.get_variables('thor')
@ -254,6 +269,7 @@ class TestInventory(unittest.TestCase):
expected2 = ['rtp_a', 'rtp_b']
expected3 = ['rtp_a', 'rtp_b', 'rtp_c', 'tri_a', 'tri_b', 'tri_c']
expected4 = ['rtp_b', 'orlando' ]
expected5 = ['blade-a-1']
inventory = self.complex_inventory()
hosts = inventory.list_hosts("nc[1]")
@ -264,6 +280,8 @@ class TestInventory(unittest.TestCase):
self.compare(hosts, expected3, sort=False)
hosts = inventory.list_hosts("nc[1-2]:florida[0-1]")
self.compare(hosts, expected4, sort=False)
hosts = inventory.list_hosts("blade-a-1")
self.compare(hosts, expected5, sort=False)
def test_complex_intersect(self):
inventory = self.complex_inventory()

@ -87,3 +87,9 @@ host[2:3]
[role3]
host[1:3:2]
[role4]
blade-[a:c]-[1:16]
blade-[d:z]-[01:16].example.com
blade-[1:10]-[1:16]
host-e-[10:16].example.net:1234

Loading…
Cancel
Save