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
46a4ae74
Commit
46a4ae74
authored
Oct 08, 2012
by
Jeroen Hoekx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add inventory variables to hostvars.
Look up only when requested and cache the result.
parent
f32778aa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
1 deletions
+17
-1
lib/ansible/runner/__init__.py
+17
-1
No files found.
lib/ansible/runner/__init__.py
View file @
46a4ae74
...
...
@@ -69,6 +69,22 @@ def _executor_hook(job_queue, result_queue):
except
:
traceback
.
print_exc
()
class
HostVars
(
dict
):
''' A special view of setup_cache that adds values from the inventory
when needed. '''
def
__init__
(
self
,
setup_cache
,
inventory
):
self
.
setup_cache
=
setup_cache
self
.
inventory
=
inventory
self
.
lookup
=
{}
self
.
update
(
setup_cache
)
def
__getitem__
(
self
,
host
):
if
not
host
in
self
.
lookup
:
self
.
lookup
[
host
]
=
self
.
inventory
.
get_variables
(
host
)
self
.
setup_cache
[
host
]
.
update
(
self
.
lookup
[
host
])
return
self
.
setup_cache
[
host
]
class
Runner
(
object
):
''' core API interface to ansible '''
...
...
@@ -252,7 +268,7 @@ class Runner(object):
inject
.
update
(
host_variables
)
inject
.
update
(
self
.
module_vars
)
inject
.
update
(
self
.
setup_cache
[
host
])
inject
[
'hostvars'
]
=
self
.
setup_cache
inject
[
'hostvars'
]
=
HostVars
(
self
.
setup_cache
,
self
.
inventory
)
inject
[
'group_names'
]
=
host_variables
.
get
(
'group_names'
,
[])
inject
[
'groups'
]
=
self
.
inventory
.
groups_list
()
...
...
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