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
39393482
Commit
39393482
authored
Jul 31, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix HostVars to support containment tests
parent
8e164eb4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
2 deletions
+15
-2
lib/ansible/vars/hostvars.py
+15
-2
No files found.
lib/ansible/vars/hostvars.py
View file @
39393482
...
...
@@ -19,13 +19,16 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
import
collections
from
jinja2
import
Undefined
as
j2undefined
from
ansible.template
import
Templar
__all__
=
[
'HostVars'
]
class
HostVars
(
dict
):
# Note -- this is a Mapping, not a MutableMapping
class
HostVars
(
collections
.
Mapping
):
''' A special view of vars_cache that adds values from the inventory when needed. '''
def
__init__
(
self
,
vars_manager
,
play
,
inventory
,
loader
):
...
...
@@ -36,7 +39,7 @@ class HostVars(dict):
self
.
_lookup
=
{}
def
__getitem__
(
self
,
host_name
):
if
host_name
not
in
self
.
_lookup
:
host
=
self
.
_inventory
.
get_host
(
host_name
)
if
not
host
:
...
...
@@ -46,3 +49,13 @@ class HostVars(dict):
self
.
_lookup
[
host_name
]
=
templar
.
template
(
result
,
fail_on_undefined
=
False
)
return
self
.
_lookup
[
host_name
]
def
__contains__
(
self
,
host_name
):
item
=
self
.
get
(
host_name
)
if
item
and
item
is
not
j2undefined
:
return
True
return
False
def
__iter__
(
self
):
raise
NotImplementedError
(
'HostVars does not support iteration as hosts are discovered on an as needed basis.'
)
def
__len__
(
self
):
raise
NotImplementedError
(
'HostVars does not support len. hosts entries are discovered dynamically as needed'
)
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