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
95c6fe88
Commit
95c6fe88
authored
Sep 23, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of conditional vars_files which contain variables
Fixes #12484
parent
c83f51b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
21 deletions
+27
-21
lib/ansible/vars/__init__.py
+27
-21
No files found.
lib/ansible/vars/__init__.py
View file @
95c6fe88
...
@@ -33,7 +33,7 @@ except ImportError:
...
@@ -33,7 +33,7 @@ except ImportError:
from
ansible
import
constants
as
C
from
ansible
import
constants
as
C
from
ansible.cli
import
CLI
from
ansible.cli
import
CLI
from
ansible.errors
import
AnsibleError
,
AnsibleUndefinedVariable
from
ansible.errors
import
AnsibleError
,
Ansible
ParserError
,
Ansible
UndefinedVariable
from
ansible.inventory.host
import
Host
from
ansible.inventory.host
import
Host
from
ansible.parsing
import
DataLoader
from
ansible.parsing
import
DataLoader
from
ansible.plugins.cache
import
FactCache
from
ansible.plugins.cache
import
FactCache
...
@@ -221,28 +221,34 @@ class VariableManager:
...
@@ -221,28 +221,34 @@ class VariableManager:
all_vars
=
combine_vars
(
all_vars
,
play
.
get_vars
())
all_vars
=
combine_vars
(
all_vars
,
play
.
get_vars
())
for
vars_file_item
in
play
.
get_vars_files
():
for
vars_file_item
in
play
.
get_vars_files
():
# create a set of temporary vars here, which incorporate the
# extra vars so we can properly template the vars_files entries
temp_vars
=
combine_vars
(
all_vars
,
self
.
_extra_vars
)
templar
=
Templar
(
loader
=
loader
,
variables
=
temp_vars
)
# we assume each item in the list is itself a list, as we
# support "conditional includes" for vars_files, which mimics
# the with_first_found mechanism.
#vars_file_list = templar.template(vars_file_item)
vars_file_list
=
vars_file_item
if
not
isinstance
(
vars_file_list
,
list
):
vars_file_list
=
[
vars_file_list
]
# now we iterate through the (potential) files, and break out
# as soon as we read one from the list. If none are found, we
# raise an error, which is silently ignored at this point.
try
:
try
:
# create a set of temporary vars here, which incorporate the
# extra vars so we can properly template the vars_files entries
temp_vars
=
combine_vars
(
all_vars
,
self
.
_extra_vars
)
templar
=
Templar
(
loader
=
loader
,
variables
=
temp_vars
)
# we assume each item in the list is itself a list, as we
# support "conditional includes" for vars_files, which mimics
# the with_first_found mechanism.
vars_file_list
=
templar
.
template
(
vars_file_item
)
if
not
isinstance
(
vars_file_list
,
list
):
vars_file_list
=
[
vars_file_list
]
# now we iterate through the (potential) files, and break out
# as soon as we read one from the list. If none are found, we
# raise an error, which is silently ignored at this point.
for
vars_file
in
vars_file_list
:
for
vars_file
in
vars_file_list
:
data
=
preprocess_vars
(
loader
.
load_from_file
(
vars_file
))
vars_file
=
templar
.
template
(
vars_file
)
if
data
is
not
None
:
try
:
for
item
in
data
:
data
=
preprocess_vars
(
loader
.
load_from_file
(
vars_file
))
all_vars
=
combine_vars
(
all_vars
,
item
)
if
data
is
not
None
:
break
for
item
in
data
:
all_vars
=
combine_vars
(
all_vars
,
item
)
break
except
AnsibleParserError
as
e
:
# we continue on loader failures
continue
else
:
else
:
raise
AnsibleError
(
"vars file
%
s was not found"
%
vars_file_item
)
raise
AnsibleError
(
"vars file
%
s was not found"
%
vars_file_item
)
except
(
UndefinedError
,
AnsibleUndefinedVariable
):
except
(
UndefinedError
,
AnsibleUndefinedVariable
):
...
...
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