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
cfb7c94c
Commit
cfb7c94c
authored
Apr 28, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #271 from jhoekx/group-names
Introduce group_names in template variables.
parents
6341361a
b87710a1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
11 deletions
+33
-11
lib/ansible/inventory.py
+10
-4
test/TestInventory.py
+18
-7
test/yaml_hosts
+5
-0
No files found.
lib/ansible/inventory.py
View file @
cfb7c94c
...
...
@@ -81,13 +81,19 @@ class Inventory(object):
def
get_variables
(
self
,
host
):
""" Return the variables associated with this host. """
variables
=
{}
if
host
in
self
.
_variables
:
return
self
.
_variables
[
host
]
.
copy
()
variables
.
update
(
self
.
_variables
[
host
]
.
copy
())
if
self
.
_is_script
:
variables
.
update
(
self
.
_get_variables_from_script
(
host
))
if
not
self
.
_is_script
:
return
{}
variables
[
'group_names'
]
=
[]
for
name
,
hosts
in
self
.
groups
.
iteritems
():
if
host
in
hosts
:
variables
[
'group_names'
]
.
append
(
name
)
return
self
.
_get_variables_from_script
(
host
)
return
variables
# *****************************************************
...
...
test/TestInventory.py
View file @
cfb7c94c
...
...
@@ -85,13 +85,13 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
simple_inventory
()
vars
=
inventory
.
get_variables
(
'thor'
)
assert
vars
==
{}
assert
vars
==
{
'group_names'
:
[
'norse'
]
}
def
test_simple_port
(
self
):
inventory
=
self
.
simple_inventory
()
vars
=
inventory
.
get_variables
(
'hera'
)
assert
vars
==
{
'ansible_ssh_port'
:
3000
}
assert
vars
==
{
'ansible_ssh_port'
:
3000
,
'group_names'
:
[
'greek'
]
}
### Inventory API tests
...
...
@@ -146,7 +146,7 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
script_inventory
()
vars
=
inventory
.
get_variables
(
'thor'
)
assert
vars
==
{
"hammer"
:
True
}
assert
vars
==
{
"hammer"
:
True
,
'group_names'
:
[
'norse'
]
}
### Tests for yaml inventory file
...
...
@@ -205,7 +205,7 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'thor'
)
assert
vars
==
{
"hammer"
:
True
}
assert
vars
==
{
"hammer"
:
True
,
'group_names'
:
[
'norse'
]
}
def
test_yaml_change_vars
(
self
):
inventory
=
self
.
yaml_inventory
()
...
...
@@ -214,19 +214,30 @@ class TestInventory(unittest.TestCase):
vars
[
"hammer"
]
=
False
vars
=
inventory
.
get_variables
(
'thor'
)
assert
vars
==
{
"hammer"
:
True
}
assert
vars
==
{
"hammer"
:
True
,
'group_names'
:
[
'norse'
]
}
def
test_yaml_host_vars
(
self
):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'saturn'
)
assert
vars
==
{
"moon"
:
"titan"
,
"moon2"
:
"enceladus"
}
assert
vars
==
{
"moon"
:
"titan"
,
"moon2"
:
"enceladus"
,
'group_names'
:
[
'multiple'
]}
def
test_yaml_port
(
self
):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'hera'
)
assert
vars
==
{
'ansible_ssh_port'
:
3000
,
'ntp_server'
:
'olympus.example.com'
}
assert
vars
==
{
'ansible_ssh_port'
:
3000
,
'ntp_server'
:
'olympus.example.com'
,
'group_names'
:
[
'greek'
]}
def
test_yaml_multiple_groups
(
self
):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'odin'
)
assert
'group_names'
in
vars
assert
sorted
(
vars
[
'group_names'
])
==
[
'norse'
,
'ruler'
]
### Test Runner class method
...
...
test/yaml_hosts
View file @
cfb7c94c
...
...
@@ -25,6 +25,11 @@
- odin
- loki
- group: ruler
hosts:
- zeus
- odin
- group: multiple
hosts:
- saturn
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