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
1af461f4
Commit
1af461f4
authored
May 08, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #330 from jhoekx/yaml-inventory-list
Yaml inventory variable list
parents
9b741a1d
e09572a8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
8 deletions
+23
-8
lib/ansible/inventory_parser.py
+4
-4
lib/ansible/inventory_parser_yaml.py
+6
-1
test/TestInventory.py
+10
-2
test/yaml_hosts
+3
-1
No files found.
lib/ansible/inventory_parser.py
View file @
1af461f4
...
...
@@ -54,12 +54,12 @@ class InventoryParser(object):
def
_parse_base_groups
(
self
):
un
defined
=
Group
(
name
=
'undefin
ed'
)
un
grouped
=
Group
(
name
=
'ungroup
ed'
)
all
=
Group
(
name
=
'all'
)
all
.
add_child_group
(
un
defin
ed
)
all
.
add_child_group
(
un
group
ed
)
self
.
groups
=
dict
(
all
=
all
,
un
defined
=
undefin
ed
)
active_group_name
=
'un
defin
ed'
self
.
groups
=
dict
(
all
=
all
,
un
grouped
=
ungroup
ed
)
active_group_name
=
'un
group
ed'
for
line
in
self
.
lines
:
if
line
.
startswith
(
"["
):
...
...
lib/ansible/inventory_parser_yaml.py
View file @
1af461f4
...
...
@@ -63,7 +63,12 @@ class InventoryParserYaml(object):
elif
type
(
item
)
==
dict
and
'host'
in
item
:
host
=
self
.
_make_host
(
item
[
'host'
])
for
(
k
,
v
)
in
item
.
get
(
'vars'
,{})
.
items
():
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
:
...
...
test/TestInventory.py
View file @
1af461f4
...
...
@@ -221,11 +221,11 @@ class TestInventory(unittest.TestCase):
expected_hosts
=
[
'thor'
,
'odin'
,
'loki'
]
self
.
compare
(
hosts
,
expected_hosts
)
def
test_
simple
_ungrouped
(
self
):
def
test_
yaml
_ungrouped
(
self
):
inventory
=
self
.
yaml_inventory
()
hosts
=
inventory
.
list_hosts
(
"ungrouped"
)
expected_hosts
=
[
'jupiter'
,
'zeus'
]
expected_hosts
=
[
'jupiter'
]
self
.
compare
(
hosts
,
expected_hosts
)
def
test_yaml_combined
(
self
):
...
...
@@ -258,6 +258,14 @@ class TestInventory(unittest.TestCase):
'hammer'
:
True
,
'inventory_hostname'
:
'thor'
}
def
test_yaml_list_vars
(
self
):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'zeus'
)
assert
vars
==
{
'ansible_ssh_port'
:
3001
,
'group_names'
:
[
'greek'
,
'ruler'
],
'inventory_hostname'
:
'zeus'
,
'ntp_server'
:
'olympus.example.com'
}
def
test_yaml_change_vars
(
self
):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'thor'
)
...
...
test/yaml_hosts
View file @
1af461f4
...
...
@@ -6,7 +6,9 @@
moon: titan
moon2: enceladus
- zeus
- host: zeus
vars:
- ansible_ssh_port: 3001
- group: greek
hosts:
...
...
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