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
03541bab
Commit
03541bab
authored
May 02, 2012
by
Jeroen Hoekx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Define 'inventory_hostname' variable for hosts.
parent
594084bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
9 deletions
+23
-9
lib/ansible/inventory.py
+4
-1
test/TestInventory.py
+19
-8
No files found.
lib/ansible/inventory.py
View file @
03541bab
...
...
@@ -81,7 +81,10 @@ class Inventory(object):
def
get_variables
(
self
,
host
):
""" Return the variables associated with this host. """
variables
=
{}
variables
=
{
'inventory_hostname'
:
host
,
}
if
host
in
self
.
_variables
:
variables
.
update
(
self
.
_variables
[
host
]
.
copy
())
...
...
test/TestInventory.py
View file @
03541bab
...
...
@@ -85,13 +85,16 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
simple_inventory
()
vars
=
inventory
.
get_variables
(
'thor'
)
assert
vars
==
{
'group_names'
:
[
'norse'
]}
assert
vars
==
{
'group_names'
:
[
'norse'
],
'inventory_hostname'
:
'thor'
}
def
test_simple_port
(
self
):
inventory
=
self
.
simple_inventory
()
vars
=
inventory
.
get_variables
(
'hera'
)
assert
vars
==
{
'ansible_ssh_port'
:
3000
,
'group_names'
:
[
'greek'
]}
assert
vars
==
{
'ansible_ssh_port'
:
3000
,
'group_names'
:
[
'greek'
],
'inventory_hostname'
:
'hera'
}
### Inventory API tests
...
...
@@ -146,7 +149,9 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
script_inventory
()
vars
=
inventory
.
get_variables
(
'thor'
)
assert
vars
==
{
"hammer"
:
True
,
'group_names'
:
[
'norse'
]}
assert
vars
==
{
'hammer'
:
True
,
'group_names'
:
[
'norse'
],
'inventory_hostname'
:
'thor'
}
### Tests for yaml inventory file
...
...
@@ -204,8 +209,10 @@ class TestInventory(unittest.TestCase):
def
test_yaml_vars
(
self
):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'thor'
)
assert
vars
==
{
"hammer"
:
True
,
'group_names'
:
[
'norse'
]}
print
vars
assert
vars
==
{
'group_names'
:
[
'norse'
],
'hammer'
:
True
,
'inventory_hostname'
:
'thor'
}
def
test_yaml_change_vars
(
self
):
inventory
=
self
.
yaml_inventory
()
...
...
@@ -214,14 +221,17 @@ class TestInventory(unittest.TestCase):
vars
[
"hammer"
]
=
False
vars
=
inventory
.
get_variables
(
'thor'
)
assert
vars
==
{
"hammer"
:
True
,
'group_names'
:
[
'norse'
]}
assert
vars
==
{
'hammer'
:
True
,
'inventory_hostname'
:
'thor'
,
'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
==
{
'inventory_hostname'
:
'saturn'
,
'moon'
:
'titan'
,
'moon2'
:
'enceladus'
,
'group_names'
:
[
'multiple'
]}
def
test_yaml_port
(
self
):
...
...
@@ -229,6 +239,7 @@ class TestInventory(unittest.TestCase):
vars
=
inventory
.
get_variables
(
'hera'
)
assert
vars
==
{
'ansible_ssh_port'
:
3000
,
'inventory_hostname'
:
'hera'
,
'ntp_server'
:
'olympus.example.com'
,
'group_names'
:
[
'greek'
]}
...
...
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