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
961ccdb2
Commit
961ccdb2
authored
Apr 16, 2012
by
Jeroen Hoekx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
List hosts in no group in the ungrouped group.
parent
3a24aa9a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
1 deletions
+32
-1
lib/ansible/inventory.py
+16
-1
test/TestInventory.py
+14
-0
test/yaml_hosts
+2
-0
No files found.
lib/ansible/inventory.py
View file @
961ccdb2
...
...
@@ -168,6 +168,8 @@ class Inventory(object):
hosts
=
[]
groups
=
{}
ungrouped
=
[]
for
item
in
data
:
if
type
(
item
)
==
dict
:
if
"group"
in
item
:
...
...
@@ -186,13 +188,14 @@ class Inventory(object):
groups
[
group_name
]
=
group_hosts
hosts
.
extend
(
group_hosts
)
# or a host
elif
"host"
in
item
:
host_name
=
self
.
_parse_yaml_host
(
item
)
hosts
.
append
(
host_name
)
ungrouped
.
append
(
host_name
)
else
:
host_name
=
self
.
_parse_yaml_host
(
item
)
hosts
.
append
(
host_name
)
ungrouped
.
append
(
host_name
)
# filter duplicate hosts
output_hosts
=
[]
...
...
@@ -200,6 +203,18 @@ class Inventory(object):
if
host
not
in
output_hosts
:
output_hosts
.
append
(
host
)
if
len
(
ungrouped
)
>
0
:
# hosts can be defined top-level, but also in a group
really_ungrouped
=
[]
for
host
in
ungrouped
:
already_grouped
=
False
for
name
,
group_hosts
in
groups
.
items
():
if
host
in
group_hosts
:
already_grouped
=
True
if
not
already_grouped
:
really_ungrouped
.
append
(
host
)
groups
[
"ungrouped"
]
=
really_ungrouped
return
output_hosts
,
groups
def
_parse_yaml_host
(
self
,
item
,
variables
=
[]):
...
...
test/TestInventory.py
View file @
961ccdb2
...
...
@@ -51,6 +51,13 @@ class TestInventory(unittest.TestCase):
expected_hosts
=
[
'thor'
,
'odin'
,
'loki'
]
assert
hosts
==
expected_hosts
def
test_simple_ungrouped
(
self
):
inventory
=
self
.
simple_inventory
()
hosts
=
inventory
.
list_hosts
(
"ungrouped"
)
expected_hosts
=
[
'jupiter'
,
'saturn'
]
assert
hosts
==
expected_hosts
def
test_simple_combined
(
self
):
inventory
=
self
.
simple_inventory
()
hosts
=
inventory
.
list_hosts
(
"norse:greek"
)
...
...
@@ -176,6 +183,13 @@ class TestInventory(unittest.TestCase):
expected_hosts
=
[
'thor'
,
'odin'
,
'loki'
]
assert
hosts
==
expected_hosts
def
test_simple_ungrouped
(
self
):
inventory
=
self
.
yaml_inventory
()
hosts
=
inventory
.
list_hosts
(
"ungrouped"
)
expected_hosts
=
[
'jupiter'
]
assert
hosts
==
expected_hosts
def
test_yaml_combined
(
self
):
inventory
=
self
.
yaml_inventory
()
hosts
=
inventory
.
list_hosts
(
"norse:greek"
)
...
...
test/yaml_hosts
View file @
961ccdb2
...
...
@@ -5,6 +5,8 @@
vars:
- moon: titan
- zeus
- group: greek
hosts:
- zeus
...
...
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