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
a18f811b
Commit
a18f811b
authored
Feb 24, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'jimi-c-issue_4620' into devel
parents
0f95a905
f23ccebb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
lib/ansible/inventory/__init__.py
+12
-17
test/units/TestInventory.py
+5
-0
No files found.
lib/ansible/inventory/__init__.py
View file @
a18f811b
...
...
@@ -207,24 +207,19 @@ class Inventory(object):
a tuple of (start, stop) or None
"""
if
not
"["
in
pattern
or
pattern
.
startswith
(
'~'
):
return
(
pattern
,
None
)
(
first
,
rest
)
=
pattern
.
split
(
"["
)
rest
=
rest
.
replace
(
"]"
,
""
)
try
:
# support selectors like webservers[0]
x
=
int
(
rest
)
return
(
first
,
(
x
,
x
))
except
:
pass
if
"-"
in
rest
:
(
left
,
right
)
=
rest
.
split
(
"-"
,
1
)
return
(
first
,
(
left
,
right
))
elif
":"
in
rest
:
(
left
,
right
)
=
rest
.
split
(
":"
,
1
)
return
(
first
,
(
left
,
right
))
# The regex used to match on the range, which can be [x] or [x-y].
pattern_re
=
re
.
compile
(
"^(.*)
\
[([0-9]+)(?:(?:-)([0-9]+))?
\
](.*)$"
)
m
=
pattern_re
.
match
(
pattern
)
if
m
:
(
target
,
first
,
last
,
rest
)
=
m
.
groups
()
first
=
int
(
first
)
if
last
:
last
=
int
(
last
)
else
:
last
=
first
return
(
target
,
(
first
,
last
))
else
:
return
(
first
,
(
rest
,
rest
)
)
return
(
pattern
,
None
)
def
_apply_ranges
(
self
,
pat
,
hosts
):
"""
...
...
test/units/TestInventory.py
View file @
a18f811b
...
...
@@ -207,6 +207,11 @@ class TestInventory(unittest.TestCase):
inventory
.
subset
(
'odin;thor,loki'
)
self
.
assertEqual
(
sorted
(
inventory
.
list_hosts
()),
sorted
([
'thor'
,
'odin'
,
'loki'
]))
def
test_subset_range
(
self
):
inventory
=
self
.
simple_inventory
()
inventory
.
subset
(
'greek[0-2];norse[0]'
)
self
.
assertEqual
(
sorted
(
inventory
.
list_hosts
()),
sorted
([
'zeus'
,
'hera'
,
'thor'
]))
def
test_subset_filename
(
self
):
inventory
=
self
.
simple_inventory
()
inventory
.
subset
(
'@'
+
os
.
path
.
join
(
self
.
test_dir
,
'restrict_pattern'
))
...
...
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