diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py index 4b1607d8844..17aee923b9a 100644 --- a/lib/ansible/inventory/ini.py +++ b/lib/ansible/inventory/ini.py @@ -24,6 +24,7 @@ from ansible.inventory.expand_hosts import detect_range from ansible.inventory.expand_hosts import expand_hostname_range from ansible import errors import shlex +import re class InventoryParser(object): """ @@ -167,5 +168,8 @@ class InventoryParser(object): if line.find("=") == -1: raise errors.AnsibleError("variables assigned to group must be in key=value form") else: - (k,v) = line.split("=",1) - group.set_variable(k,v) + (k, v) = [e.strip() for e in line.split("=", 1)] + if re.match(r"^(['\"]).*\1$", v): + group.set_variable(k, re.sub(r"^['\"]|['\"]$", '', v)) + else: + group.set_variable(k, v) diff --git a/test/TestInventory.py b/test/TestInventory.py index a089aa1a749..2a0bd8d6f6f 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -142,7 +142,9 @@ class TestInventory(unittest.TestCase): print vars expected = dict( - a='1', b='2', c='3', d='10002', rga='1', rgb='2', rgc='3', + a='1', b='2', c='3', d='10002', e='10003', f='10004 != 10005', + g=' g ', h=' h ', i="' i \"", j='" j', + rga='1', rgb='2', rgc='3', inventory_hostname='rtp_a', inventory_hostname_short='rtp_a', group_names=[ 'eastcoast', 'nc', 'redundantgroup', 'redundantgroup2', 'redundantgroup3', 'rtp', 'us' ] ) diff --git a/test/complex_hosts b/test/complex_hosts index 8c2c726f3be..0c568161c3a 100644 --- a/test/complex_hosts +++ b/test/complex_hosts @@ -34,6 +34,12 @@ rgc=3 b=10000 c=10001 d=10002 +e = 10003 + f = 10004 != 10005 + g = " g " + h = ' h ' + i = ' i " + j = " j [rtp] rtp_a