Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
9da26da3
Commit
9da26da3
authored
Mar 17, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ini_vars' of
git://github.com/dmage/ansible
into devel
parents
13f69dad
f6a4c20c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
24 deletions
+20
-24
lib/ansible/inventory/ini.py
+16
-22
test/units/TestInventory.py
+3
-2
test/units/inventory_test_data/complex_hosts
+1
-0
No files found.
lib/ansible/inventory/ini.py
View file @
9da26da3
...
@@ -48,6 +48,20 @@ class InventoryParser(object):
...
@@ -48,6 +48,20 @@ class InventoryParser(object):
self
.
_parse_group_variables
()
self
.
_parse_group_variables
()
return
self
.
groups
return
self
.
groups
@staticmethod
def
_parse_value
(
v
):
if
"#"
not
in
v
:
try
:
return
ast
.
literal_eval
(
v
)
# Using explicit exceptions.
# Likely a string that literal_eval does not like. We wil then just set it.
except
ValueError
:
# For some reason this was thought to be malformed.
pass
except
SyntaxError
:
# Is this a hash with an equals at the end?
pass
return
v
# [webservers]
# [webservers]
# alpha
# alpha
...
@@ -123,22 +137,7 @@ class InventoryParser(object):
...
@@ -123,22 +137,7 @@ class InventoryParser(object):
(
k
,
v
)
=
t
.
split
(
"="
,
1
)
(
k
,
v
)
=
t
.
split
(
"="
,
1
)
except
ValueError
,
e
:
except
ValueError
,
e
:
raise
errors
.
AnsibleError
(
"Invalid ini entry:
%
s -
%
s"
%
(
t
,
str
(
e
)))
raise
errors
.
AnsibleError
(
"Invalid ini entry:
%
s -
%
s"
%
(
t
,
str
(
e
)))
host
.
set_variable
(
k
,
self
.
_parse_value
(
v
))
# If there is a hash in the value don't pass it through to ast at ast will split at the hash.
if
"#"
in
v
:
host
.
set_variable
(
k
,
v
)
else
:
try
:
host
.
set_variable
(
k
,
ast
.
literal_eval
(
v
))
# Using explicit exceptions.
# Likely a string that literal_eval does not like. We wil then just set it.
except
ValueError
:
# For some reason this was thought to be malformed.
host
.
set_variable
(
k
,
v
)
except
SyntaxError
:
# Is this a hash with an equals at the end?
host
.
set_variable
(
k
,
v
)
self
.
groups
[
active_group_name
]
.
add_host
(
host
)
self
.
groups
[
active_group_name
]
.
add_host
(
host
)
# [southeast:children]
# [southeast:children]
...
@@ -193,12 +192,7 @@ class InventoryParser(object):
...
@@ -193,12 +192,7 @@ class InventoryParser(object):
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
)
=
[
e
.
strip
()
for
e
in
line
.
split
(
"="
,
1
)]
(
k
,
v
)
=
[
e
.
strip
()
for
e
in
line
.
split
(
"="
,
1
)]
# When the value is a single-quoted or double-quoted string
group
.
set_variable
(
k
,
self
.
_parse_value
(
v
))
if
re
.
match
(
r"^(['\"]).*\1$"
,
v
):
# Unquote the string
group
.
set_variable
(
k
,
re
.
sub
(
r"^['\"]|['\"]$"
,
''
,
v
))
else
:
group
.
set_variable
(
k
,
v
)
def
get_host_variables
(
self
,
host
):
def
get_host_variables
(
self
,
host
):
return
{}
return
{}
test/units/TestInventory.py
View file @
9da26da3
...
@@ -236,9 +236,10 @@ class TestInventory(unittest.TestCase):
...
@@ -236,9 +236,10 @@ class TestInventory(unittest.TestCase):
print
vars
print
vars
expected
=
dict
(
expected
=
dict
(
a
=
'1'
,
b
=
'2'
,
c
=
'3'
,
d
=
'10002'
,
e
=
'10003'
,
f
=
'10004 != 10005'
,
a
=
1
,
b
=
2
,
c
=
3
,
d
=
10002
,
e
=
10003
,
f
=
'10004 != 10005'
,
g
=
' g '
,
h
=
' h '
,
i
=
"' i
\"
"
,
j
=
'" j'
,
g
=
' g '
,
h
=
' h '
,
i
=
"' i
\"
"
,
j
=
'" j'
,
rga
=
'1'
,
rgb
=
'2'
,
rgc
=
'3'
,
k
=
[
'k1'
,
'k2'
],
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'
]
)
)
...
...
test/units/inventory_test_data/complex_hosts
View file @
9da26da3
...
@@ -40,6 +40,7 @@ e = 10003
...
@@ -40,6 +40,7 @@ e = 10003
h = ' h '
h = ' h '
i = ' i "
i = ' i "
j = " j
j = " j
k = ['k1', 'k2']
[rtp]
[rtp]
rtp_a
rtp_a
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment