1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Allows whitespaces around assignment operators

when defining group variables
This commit is contained in:
Junegunn Choi 2012-12-14 20:43:29 +09:00
parent 23f2a7fc7e
commit daf797804b
3 changed files with 15 additions and 3 deletions

View file

@ -24,6 +24,7 @@ from ansible.inventory.expand_hosts import detect_range
from ansible.inventory.expand_hosts import expand_hostname_range from ansible.inventory.expand_hosts import expand_hostname_range
from ansible import errors from ansible import errors
import shlex import shlex
import re
class InventoryParser(object): class InventoryParser(object):
""" """
@ -167,5 +168,8 @@ class InventoryParser(object):
if line.find("=") == -1: if line.find("=") == -1:
raise errors.AnsibleError("variables assigned to group must be in key=value form") raise errors.AnsibleError("variables assigned to group must be in key=value form")
else: else:
(k,v) = line.split("=",1) (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) group.set_variable(k, v)

View file

@ -142,7 +142,9 @@ class TestInventory(unittest.TestCase):
print vars print vars
expected = dict( 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', inventory_hostname='rtp_a', inventory_hostname_short='rtp_a',
group_names=[ 'eastcoast', 'nc', 'redundantgroup', 'redundantgroup2', 'redundantgroup3', 'rtp', 'us' ] group_names=[ 'eastcoast', 'nc', 'redundantgroup', 'redundantgroup2', 'redundantgroup3', 'rtp', 'us' ]
) )

View file

@ -34,6 +34,12 @@ rgc=3
b=10000 b=10000
c=10001 c=10001
d=10002 d=10002
e = 10003
f = 10004 != 10005
g = " g "
h = ' h '
i = ' i "
j = " j
[rtp] [rtp]
rtp_a rtp_a