mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Support «hosts: groupname[1:]» notation (~= 'the rest of the group')
This commit is contained in:
parent
21142f5723
commit
2fcdb37e7b
3 changed files with 13 additions and 5 deletions
|
@ -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] ]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue