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
2fcdb37e
Commit
2fcdb37e
authored
Sep 18, 2015
by
Abhijit Menon-Sen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support «hosts: groupname[1:]» notation (~= 'the rest of the group')
parent
21142f57
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
5 deletions
+13
-5
docsite/rst/intro_patterns.rst
+3
-2
lib/ansible/inventory/__init__.py
+7
-3
test/units/inventory/test_inventory.py
+3
-0
No files found.
docsite/rst/intro_patterns.rst
View file @
2fcdb37e
...
...
@@ -79,8 +79,9 @@ You can refer to hosts within the group by adding a subscript to the group name:
webservers[0] # == cobweb
webservers[-1] # == weber
webservers[0:1] # == webservers[0]:webservers[1]
# == cobweb:webbing
webservers[0:1] # == webservers[0],webservers[1]
# == cobweb,webbing
webservers[1:] # == webbing,weber
Most people don't specify patterns as regular expressions, but you can. Just start the pattern with a '~'::
...
...
lib/ansible/inventory/__init__.py
View file @
2fcdb37e
...
...
@@ -342,9 +342,9 @@ class Inventory(object):
r'''^
(.+) # A pattern expression ending with...
\[(?: # A [subscript] expression comprising:
(-?[0-9]+)
# A single positive or negative number
| # Or a numeric range
([0-9]
+)([:-])([0-9]+
)
(-?[0-9]+)
|
# A single positive or negative number
([0-9]+)([:-]) # Or an x:y or x: range.
([0-9]
*
)
)\]
$
'''
,
re
.
X
...
...
@@ -357,6 +357,8 @@ class Inventory(object):
if
idx
:
subscript
=
(
int
(
idx
),
None
)
else
:
if
not
end
:
end
=
-
1
subscript
=
(
int
(
start
),
int
(
end
))
if
sep
==
'-'
:
display
.
deprecated
(
"Use [x:y] inclusive subscripts instead of [x-y]"
,
version
=
2.0
,
removed
=
True
)
...
...
@@ -375,6 +377,8 @@ class Inventory(object):
(
start
,
end
)
=
subscript
if
end
:
if
end
==
-
1
:
end
=
len
(
hosts
)
-
1
return
hosts
[
start
:
end
+
1
]
else
:
return
[
hosts
[
start
]
]
...
...
test/units/inventory/test_inventory.py
View file @
2fcdb37e
...
...
@@ -66,6 +66,9 @@ class TestInventory(unittest.TestCase):
'a[2:3]'
:
[(
'a'
,
(
2
,
3
)),
[
'c'
,
'd'
]],
'a[-1]'
:
[(
'a'
,
(
-
1
,
None
)),
[
'Z'
]],
'a[-2]'
:
[(
'a'
,
(
-
2
,
None
)),
[
'Y'
]],
'a[48:]'
:
[(
'a'
,
(
48
,
-
1
)),
[
'W'
,
'X'
,
'Y'
,
'Z'
]],
'a[49:]'
:
[(
'a'
,
(
49
,
-
1
)),
[
'X'
,
'Y'
,
'Z'
]],
'a[1:]'
:
[(
'a'
,
(
1
,
-
1
)),
list
(
string
.
ascii_letters
[
1
:])],
}
def
setUp
(
self
):
...
...
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