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
23a62f5a
Commit
23a62f5a
authored
Oct 10, 2012
by
Jeroen Hoekx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return multiple groups from inventory API.
parent
30c01944
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
3 deletions
+18
-3
lib/ansible/inventory/script.py
+4
-1
test/TestInventory.py
+10
-0
test/inventory_api.py
+4
-2
No files found.
lib/ansible/inventory/script.py
View file @
23a62f5a
...
@@ -35,6 +35,7 @@ class InventoryScript(object):
...
@@ -35,6 +35,7 @@ class InventoryScript(object):
self
.
groups
=
self
.
_parse
()
self
.
groups
=
self
.
_parse
()
def
_parse
(
self
):
def
_parse
(
self
):
all_hosts
=
{}
groups
=
{}
groups
=
{}
self
.
raw
=
utils
.
parse_json
(
self
.
data
)
self
.
raw
=
utils
.
parse_json
(
self
.
data
)
...
@@ -45,7 +46,9 @@ class InventoryScript(object):
...
@@ -45,7 +46,9 @@ class InventoryScript(object):
group
=
groups
[
group_name
]
=
Group
(
group_name
)
group
=
groups
[
group_name
]
=
Group
(
group_name
)
host
=
None
host
=
None
for
hostname
in
hosts
:
for
hostname
in
hosts
:
host
=
Host
(
hostname
)
if
not
hostname
in
all_hosts
:
all_hosts
[
hostname
]
=
Host
(
hostname
)
host
=
all_hosts
[
hostname
]
group
.
add_host
(
host
)
group
.
add_host
(
host
)
# FIXME: hack shouldn't be needed
# FIXME: hack shouldn't be needed
all
.
add_host
(
host
)
all
.
add_host
(
host
)
...
...
test/TestInventory.py
View file @
23a62f5a
...
@@ -246,3 +246,13 @@ class TestInventory(unittest.TestCase):
...
@@ -246,3 +246,13 @@ class TestInventory(unittest.TestCase):
actual_hosts
=
inventory
.
get_hosts
(
host_names
)
actual_hosts
=
inventory
.
get_hosts
(
host_names
)
actual_host_names
=
[
host
.
name
for
host
in
actual_hosts
]
actual_host_names
=
[
host
.
name
for
host
in
actual_hosts
]
assert
host_names
==
actual_host_names
assert
host_names
==
actual_host_names
def
test_script_multiple_groups
(
self
):
inventory
=
self
.
script_inventory
()
vars
=
inventory
.
get_variables
(
'zeus'
)
print
"VARS=
%
s"
%
vars
assert
vars
==
{
'inventory_hostname'
:
'zeus'
,
'inventory_hostname_short'
:
'zeus'
,
'group_names'
:
[
'greek'
,
'major-god'
]}
test/inventory_api.py
View file @
23a62f5a
...
@@ -15,13 +15,15 @@ options, args = parser.parse_args()
...
@@ -15,13 +15,15 @@ options, args = parser.parse_args()
systems
=
{
systems
=
{
"ungrouped"
:
[
"jupiter"
,
"saturn"
],
"ungrouped"
:
[
"jupiter"
,
"saturn"
],
"greek"
:
[
"zeus"
,
"hera"
,
"poseidon"
],
"greek"
:
[
"zeus"
,
"hera"
,
"poseidon"
],
"norse"
:
[
"thor"
,
"odin"
,
"loki"
]
"norse"
:
[
"thor"
,
"odin"
,
"loki"
],
"major-god"
:
[
"zeus"
,
"odin"
],
}
}
variables
=
{
variables
=
{
"thor"
:
{
"thor"
:
{
"hammer"
:
True
"hammer"
:
True
}
},
"zeus"
:
{},
}
}
if
options
.
list_hosts
==
True
:
if
options
.
list_hosts
==
True
:
...
...
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