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
14b8e2cf
Commit
14b8e2cf
authored
Sep 03, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure set_fact variables go into VARS_CACHE
Fixes #8758
parent
893f15b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
lib/ansible/playbook/__init__.py
+14
-3
test/integration/test_var_precedence.yml
+7
-0
No files found.
lib/ansible/playbook/__init__.py
View file @
14b8e2cf
...
...
@@ -487,11 +487,20 @@ class PlayBook(object):
def
_register_play_vars
(
host
,
result
):
# when 'register' is used, persist the result in the vars cache
# rather than the setup cache - vars should be transient between playbook executions
# rather than the setup cache - vars should be transient between
# playbook executions
if
'stdout'
in
result
and
'stdout_lines'
not
in
result
:
result
[
'stdout_lines'
]
=
result
[
'stdout'
]
.
splitlines
()
utils
.
update_hash
(
self
.
VARS_CACHE
,
host
,
{
task
.
register
:
result
})
def
_save_play_facts
(
host
,
facts
):
# saves play facts in SETUP_CACHE, unless the module executed was
# set_fact, in which case we add them to the VARS_CACHE
if
task
.
module_name
==
'set_fact'
:
utils
.
update_hash
(
self
.
VARS_CACHE
,
host
,
facts
)
else
:
utils
.
update_hash
(
self
.
SETUP_CACHE
,
host
,
facts
)
# add facts to the global setup cache
for
host
,
result
in
contacted
.
iteritems
():
if
'results'
in
result
:
...
...
@@ -500,11 +509,13 @@ class PlayBook(object):
for
res
in
result
[
'results'
]:
if
type
(
res
)
==
dict
:
facts
=
res
.
get
(
'ansible_facts'
,
{})
utils
.
update_hash
(
self
.
SETUP_CACHE
,
host
,
facts
)
_save_play_facts
(
host
,
facts
)
else
:
# when facts are returned, persist them in the setup cache
facts
=
result
.
get
(
'ansible_facts'
,
{})
utils
.
update_hash
(
self
.
SETUP_CACHE
,
host
,
facts
)
_save_play_facts
(
host
,
facts
)
# if requested, save the result into the registered variable name
if
task
.
register
:
_register_play_vars
(
host
,
result
)
...
...
test/integration/test_var_precedence.yml
View file @
14b8e2cf
...
...
@@ -9,13 +9,20 @@
roles
:
-
{
role
:
test_var_precedence
,
param_var
:
"
param_var"
}
tasks
:
-
name
:
register a result
command
:
echo 'BAD!'
register
:
registered_var
-
name
:
use set_fact to override the registered_var
set_fact
:
registered_var="this is from set_fact"
-
debug
:
var=extra_var
-
debug
:
var=vars_var
-
debug
:
var=vars_files_var
-
debug
:
var=vars_files_var_role
-
debug
:
var=registered_var
-
assert
:
that
:
-
'
extra_var
==
"extra_var"'
-
'
vars_var
==
"vars_var"'
-
'
vars_files_var
==
"vars_files_var"'
-
'
vars_files_var_role
==
"vars_files_var_role3"'
-
'
registered_var
==
"this
is
from
set_fact"'
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