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
b7cb0007
Commit
b7cb0007
authored
Jun 26, 2012
by
Jeroen Hoekx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly add ungrouped hosts to 'ungrouped' in YAML inventory.
parent
06773daf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
19 deletions
+30
-19
lib/ansible/inventory/yaml.py
+25
-16
test/TestInventory.py
+3
-3
test/yaml_hosts
+2
-0
No files found.
lib/ansible/inventory/yaml.py
View file @
b7cb0007
...
...
@@ -53,25 +53,13 @@ class InventoryParserYaml(object):
all
.
add_child_group
(
ungrouped
)
self
.
groups
=
dict
(
all
=
all
,
ungrouped
=
ungrouped
)
grouped_hosts
=
[]
yaml
=
utils
.
parse_yaml
(
data
)
for
item
in
yaml
:
if
type
(
item
)
in
[
str
,
unicode
]:
host
=
self
.
_make_host
(
item
)
ungrouped
.
add_host
(
host
)
elif
type
(
item
)
==
dict
and
'host'
in
item
:
host
=
self
.
_make_host
(
item
[
'host'
])
vars
=
item
.
get
(
'vars'
,
{})
if
type
(
vars
)
==
list
:
varlist
,
vars
=
vars
,
{}
for
subitem
in
varlist
:
vars
.
update
(
subitem
)
for
(
k
,
v
)
in
vars
.
items
():
host
.
set_variable
(
k
,
v
)
elif
type
(
item
)
==
dict
and
'group'
in
item
:
# first add all groups
for
item
in
yaml
:
if
type
(
item
)
==
dict
and
'group'
in
item
:
group
=
Group
(
item
[
'group'
])
for
subresult
in
item
.
get
(
'hosts'
,[]):
...
...
@@ -79,6 +67,7 @@ class InventoryParserYaml(object):
if
type
(
subresult
)
in
[
str
,
unicode
]:
host
=
self
.
_make_host
(
subresult
)
group
.
add_host
(
host
)
grouped_hosts
.
append
(
host
)
elif
type
(
subresult
)
==
dict
:
host
=
self
.
_make_host
(
subresult
[
'host'
])
vars
=
subresult
.
get
(
'vars'
,{})
...
...
@@ -92,6 +81,7 @@ class InventoryParserYaml(object):
else
:
raise
errors
.
AnsibleError
(
"unexpected type for variable"
)
group
.
add_host
(
host
)
grouped_hosts
.
append
(
host
)
vars
=
item
.
get
(
'vars'
,{})
if
type
(
vars
)
==
dict
:
...
...
@@ -106,3 +96,22 @@ class InventoryParserYaml(object):
self
.
groups
[
group
.
name
]
=
group
all
.
add_child_group
(
group
)
# add host definitions
for
item
in
yaml
:
if
type
(
item
)
in
[
str
,
unicode
]:
host
=
self
.
_make_host
(
item
)
if
host
not
in
grouped_hosts
:
ungrouped
.
add_host
(
host
)
elif
type
(
item
)
==
dict
and
'host'
in
item
:
host
=
self
.
_make_host
(
item
[
'host'
])
vars
=
item
.
get
(
'vars'
,
{})
if
type
(
vars
)
==
list
:
varlist
,
vars
=
vars
,
{}
for
subitem
in
varlist
:
vars
.
update
(
subitem
)
for
(
k
,
v
)
in
vars
.
items
():
host
.
set_variable
(
k
,
v
)
if
host
not
in
grouped_hosts
:
ungrouped
.
add_host
(
host
)
test/TestInventory.py
View file @
b7cb0007
...
...
@@ -222,14 +222,14 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
yaml_inventory
()
hosts
=
inventory
.
list_hosts
()
print
hosts
expected_hosts
=
[
'jupiter'
,
'saturn'
,
'zeus'
,
'hera'
,
'poseidon'
,
'thor'
,
'odin'
,
'loki'
]
expected_hosts
=
[
'jupiter'
,
'saturn'
,
'
mars'
,
'
zeus'
,
'hera'
,
'poseidon'
,
'thor'
,
'odin'
,
'loki'
]
self
.
compare
(
hosts
,
expected_hosts
)
def
test_yaml_all
(
self
):
inventory
=
self
.
yaml_inventory
()
hosts
=
inventory
.
list_hosts
(
'all'
)
expected_hosts
=
[
'jupiter'
,
'saturn'
,
'zeus'
,
'hera'
,
'poseidon'
,
'thor'
,
'odin'
,
'loki'
]
expected_hosts
=
[
'jupiter'
,
'saturn'
,
'
mars'
,
'
zeus'
,
'hera'
,
'poseidon'
,
'thor'
,
'odin'
,
'loki'
]
self
.
compare
(
hosts
,
expected_hosts
)
def
test_yaml_norse
(
self
):
...
...
@@ -243,7 +243,7 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
yaml_inventory
()
hosts
=
inventory
.
list_hosts
(
"ungrouped"
)
expected_hosts
=
[
'jupiter'
]
expected_hosts
=
[
'jupiter'
,
'mars'
]
self
.
compare
(
hosts
,
expected_hosts
)
def
test_yaml_combined
(
self
):
...
...
test/yaml_hosts
View file @
b7cb0007
...
...
@@ -6,6 +6,8 @@
moon: titan
moon2: enceladus
- host: mars
- host: zeus
vars:
- ansible_ssh_port: 3001
...
...
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