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
45212394
Commit
45212394
authored
Jan 22, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding in hostvars to v2 and getting more integration tests working
parent
f9d451eb
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
85 additions
and
8 deletions
+85
-8
v2/ansible/executor/task_executor.py
+5
-0
v2/ansible/inventory/__init__.py
+2
-2
v2/ansible/modules/core
+1
-1
v2/ansible/playbook/__init__.py
+1
-0
v2/ansible/playbook/playbook_include.py
+5
-0
v2/ansible/template/vars.py
+2
-1
v2/ansible/vars/__init__.py
+21
-4
v2/ansible/vars/hostvars.py
+47
-0
v2/bin/ansible-playbook
+1
-0
No files found.
v2/ansible/executor/task_executor.py
View file @
45212394
...
...
@@ -186,6 +186,11 @@ class TaskExecutor:
# Now we do final validation on the task, which sets all fields to their final values
self
.
_task
.
post_validate
(
variables
)
# And filter out any fields which were set to default(omit), and got the omit token value
omit_token
=
variables
.
get
(
'omit'
)
if
omit_token
is
not
None
:
self
.
_task
.
args
=
dict
(
filter
(
lambda
x
:
x
[
1
]
!=
omit_token
,
self
.
_task
.
args
.
iteritems
()))
# Read some values from the task, so that we can modify them if need be
retries
=
self
.
_task
.
retries
if
retries
<=
0
:
...
...
v2/ansible/inventory/__init__.py
View file @
45212394
...
...
@@ -455,12 +455,12 @@ class Inventory(object):
return
vars
def
get_var
iable
s
(
self
,
hostname
,
update_cached
=
False
,
vault_password
=
None
):
def
get_vars
(
self
,
hostname
,
update_cached
=
False
,
vault_password
=
None
):
host
=
self
.
get_host
(
hostname
)
if
not
host
:
raise
Exception
(
"host not found:
%
s"
%
hostname
)
return
host
.
get_var
iable
s
()
return
host
.
get_vars
()
def
get_host_variables
(
self
,
hostname
,
update_cached
=
False
,
vault_password
=
None
):
...
...
core
@
8ba8f5ef
Subproject commit
1dca81266289f365765b004ab8c0c62ee9d3467e
Subproject commit
8ba8f5ef4d9361a03a690a0a71a28f3c56ce5bfb
v2/ansible/playbook/__init__.py
View file @
45212394
...
...
@@ -25,6 +25,7 @@ from ansible.errors import AnsibleError, AnsibleParserError
from
ansible.parsing
import
DataLoader
from
ansible.playbook.attribute
import
Attribute
,
FieldAttribute
from
ansible.playbook.play
import
Play
from
ansible.playbook.playbook_include
import
PlaybookInclude
from
ansible.plugins
import
push_basedir
...
...
v2/ansible/playbook/playbook_include.py
View file @
45212394
...
...
@@ -18,3 +18,8 @@
# Make coding more python3-ish
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
from
ansible.playbook.base
import
Base
class
PlaybookInclude
(
Base
):
pass
v2/ansible/template/vars.py
View file @
45212394
...
...
@@ -71,7 +71,8 @@ class AnsibleJ2Vars:
# HostVars is special, return it as-is, as is the special variable
# 'vars', which contains the vars structure
if
isinstance
(
variable
,
dict
)
and
varname
==
"vars"
:
# or isinstance(var, HostVars):
from
ansible.vars.hostvars
import
HostVars
if
isinstance
(
variable
,
dict
)
and
varname
==
"vars"
or
isinstance
(
variable
,
HostVars
):
return
variable
else
:
return
self
.
_templar
.
template
(
variable
)
...
...
v2/ansible/vars/__init__.py
View file @
45212394
...
...
@@ -23,11 +23,16 @@ import os
from
collections
import
defaultdict
try
:
from
hashlib
import
sha1
except
ImportError
:
from
sha
import
sha
as
sha1
from
ansible.parsing
import
DataLoader
from
ansible.plugins.cache
import
FactCache
from
ansible.template
import
Templar
from
ansible.utils.debug
import
debug
from
ansible.vars.hostvars
import
HostVars
CACHED_VARS
=
dict
()
...
...
@@ -40,6 +45,9 @@ class VariableManager:
self
.
_extra_vars
=
defaultdict
(
dict
)
self
.
_host_vars_files
=
defaultdict
(
dict
)
self
.
_group_vars_files
=
defaultdict
(
dict
)
self
.
_inventory
=
None
self
.
_omit_token
=
'__omit_place_holder__
%
s'
%
sha1
(
os
.
urandom
(
64
))
.
hexdigest
()
def
_get_cache_entry
(
self
,
play
=
None
,
host
=
None
,
task
=
None
):
play_id
=
"NONE"
...
...
@@ -66,6 +74,9 @@ class VariableManager:
assert
isinstance
(
value
,
dict
)
self
.
_extra_vars
=
value
.
copy
()
def
set_inventory
(
self
,
inventory
):
self
.
_inventory
=
inventory
def
_merge_dicts
(
self
,
a
,
b
):
'''
Recursively merges dict b into a, so that keys
...
...
@@ -177,8 +188,15 @@ class VariableManager:
all_vars
=
self
.
_merge_dicts
(
all_vars
,
self
.
_extra_vars
)
# FIXME: we need to move the special variables from the old runner
# inject into here (HostVars?, groups, etc.)
# FIXME: make sure all special vars are here
# Finally, we create special vars
if
host
and
self
.
_inventory
is
not
None
:
hostvars
=
HostVars
(
vars_manager
=
self
,
inventory
=
self
.
_inventory
,
loader
=
loader
)
all_vars
[
'hostvars'
]
=
hostvars
# the 'omit' value alows params to be left out if the variable they are based on is undefined
all_vars
[
'omit'
]
=
self
.
_omit_token
CACHED_VARS
[
cache_entry
]
=
all_vars
...
...
@@ -229,7 +247,6 @@ class VariableManager:
(
name
,
data
)
=
self
.
_load_inventory_file
(
path
,
loader
)
self
.
_group_vars_files
[
name
]
=
data
def
set_host_facts
(
self
,
host
,
facts
):
'''
Sets or updates the given facts for a host in the fact cache.
...
...
v2/ansible/vars/hostvars.py
0 → 100644
View file @
45212394
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
from
ansible.template
import
Templar
__all__
=
[
'HostVars'
]
class
HostVars
(
dict
):
''' A special view of vars_cache that adds values from the inventory when needed. '''
def
__init__
(
self
,
vars_manager
,
inventory
,
loader
):
self
.
_vars_manager
=
vars_manager
self
.
_inventory
=
inventory
self
.
_loader
=
loader
self
.
_lookup
=
{}
#self.update(vars_cache)
def
__getitem__
(
self
,
host_name
):
if
host_name
not
in
self
.
_lookup
:
host
=
self
.
_inventory
.
get_host
(
host_name
)
result
=
self
.
_vars_manager
.
get_vars
(
loader
=
self
.
_loader
,
host
=
host
)
#result.update(self._vars_cache.get(host, {}))
#templar = Templar(variables=self._vars_cache, loader=self._loader)
#self._lookup[host] = templar.template(result)
self
.
_lookup
[
host_name
]
=
result
return
self
.
_lookup
[
host_name
]
v2/bin/ansible-playbook
View file @
45212394
...
...
@@ -139,6 +139,7 @@ def main(args):
# create the inventory, and filter it based on the subset specified (if any)
inventory
=
Inventory
(
loader
=
loader
,
variable_manager
=
variable_manager
,
host_list
=
options
.
inventory
)
variable_manager
.
set_inventory
(
inventory
)
# Note: slightly wrong, this is written so that implicit localhost
# (which is not returned in list_hosts()) is taken into account for
...
...
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