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
f9183fcb
Commit
f9183fcb
authored
Aug 21, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sergevanginderachter-issue_8704_stacktrace_varmerge' into devel
parents
8a1fbed5
b81e77cf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
lib/ansible/inventory/script.py
+8
-0
lib/ansible/utils/__init__.py
+13
-0
No files found.
lib/ansible/inventory/script.py
View file @
f9183fcb
...
...
@@ -84,10 +84,14 @@ class InventoryScript(object):
if
not
isinstance
(
data
,
dict
):
data
=
{
'hosts'
:
data
}
# is not those subkeys, then simplified syntax, host with vars
elif
not
any
(
k
in
data
for
k
in
(
'hosts'
,
'vars'
)):
data
=
{
'hosts'
:
[
group_name
],
'vars'
:
data
}
if
'hosts'
in
data
:
if
not
isinstance
(
data
[
'hosts'
],
list
):
raise
errors
.
AnsibleError
(
"You defined a group
\"
%
s
\"
with bad "
"data for the host list:
\n
%
s"
%
(
group_name
,
data
))
for
hostname
in
data
[
'hosts'
]:
if
not
hostname
in
all_hosts
:
...
...
@@ -96,6 +100,10 @@ class InventoryScript(object):
group
.
add_host
(
host
)
if
'vars'
in
data
:
if
not
isinstance
(
data
[
'vars'
],
dict
):
raise
errors
.
AnsibleError
(
"You defined a group
\"
%
s
\"
with bad "
"data for variables:
\n
%
s"
%
(
group_name
,
data
))
for
k
,
v
in
data
[
'vars'
]
.
iteritems
():
if
group
.
name
==
all
.
name
:
all
.
set_variable
(
k
,
v
)
...
...
lib/ansible/utils/__init__.py
View file @
f9183fcb
...
...
@@ -696,12 +696,23 @@ def parse_kv(args):
options
[
k
.
strip
()]
=
unquote
(
v
.
strip
())
return
options
def
_validate_both_dicts
(
a
,
b
):
if
not
(
isinstance
(
a
,
dict
)
and
isinstance
(
b
,
dict
)):
raise
errors
.
AnsibleError
(
"failed to combine variables, expected dicts but got a '
%
s' and a '
%
s'"
%
(
type
(
a
)
.
__name__
,
type
(
b
)
.
__name__
)
)
def
merge_hash
(
a
,
b
):
''' recursively merges hash b into a
keys from b take precedence over keys from a '''
result
=
{}
# we check here as well as in combine_vars() since this
# function can work recursively with nested dicts
_validate_both_dicts
(
a
,
b
)
for
dicts
in
a
,
b
:
# next, iterate over b keys and values
for
k
,
v
in
dicts
.
iteritems
():
...
...
@@ -1308,6 +1319,8 @@ def listify_lookup_plugin_terms(terms, basedir, inject):
def
combine_vars
(
a
,
b
):
_validate_both_dicts
(
a
,
b
)
if
C
.
DEFAULT_HASH_BEHAVIOUR
==
"merge"
:
return
merge_hash
(
a
,
b
)
else
:
...
...
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