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
42cfacf8
Commit
42cfacf8
authored
Jul 28, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch up the task/host overrides for PlayContext to use the compiled vars dict
Fixes #11436
parent
2d2ec058
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
36 deletions
+5
-36
lib/ansible/executor/process/worker.py
+1
-1
lib/ansible/playbook/play_context.py
+2
-32
test/units/playbook/test_play_context.py
+2
-3
No files found.
lib/ansible/executor/process/worker.py
View file @
42cfacf8
...
@@ -111,7 +111,7 @@ class WorkerProcess(multiprocessing.Process):
...
@@ -111,7 +111,7 @@ class WorkerProcess(multiprocessing.Process):
# apply the given task's information to the connection info,
# apply the given task's information to the connection info,
# which may override some fields already set by the play or
# which may override some fields already set by the play or
# the options specified on the command line
# the options specified on the command line
new_play_context
=
play_context
.
set_task_and_
host_override
(
task
=
task
,
host
=
host
)
new_play_context
=
play_context
.
set_task_and_
variable_override
(
task
=
task
,
variables
=
job_vars
)
# execute the task and build a TaskResult from the result
# execute the task and build a TaskResult from the result
debug
(
"running TaskExecutor() for
%
s/
%
s"
%
(
host
,
task
))
debug
(
"running TaskExecutor() for
%
s/
%
s"
%
(
host
,
task
))
...
...
lib/ansible/playbook/play_context.py
View file @
42cfacf8
...
@@ -275,24 +275,7 @@ class PlayContext(Base):
...
@@ -275,24 +275,7 @@ class PlayContext(Base):
elif
isinstance
(
options
.
skip_tags
,
basestring
):
elif
isinstance
(
options
.
skip_tags
,
basestring
):
self
.
skip_tags
.
update
(
options
.
skip_tags
.
split
(
','
))
self
.
skip_tags
.
update
(
options
.
skip_tags
.
split
(
','
))
#def copy(self, ci):
def
set_task_and_variable_override
(
self
,
task
,
variables
):
# '''
# Copies the connection info from another connection info object, used
# when merging in data from task overrides.
# '''
#
# for field in self._get_fields():
# value = getattr(ci, field, None)
# if isinstance(value, dict):
# setattr(self, field, value.copy())
# elif isinstance(value, set):
# setattr(self, field, value.copy())
# elif isinstance(value, list):
# setattr(self, field, value[:])
# else:
# setattr(self, field, value)
def
set_task_and_host_override
(
self
,
task
,
host
):
'''
'''
Sets attributes from the task if they are set, which will override
Sets attributes from the task if they are set, which will override
those from the play.
those from the play.
...
@@ -309,8 +292,7 @@ class PlayContext(Base):
...
@@ -309,8 +292,7 @@ class PlayContext(Base):
setattr
(
new_info
,
attr
,
attr_val
)
setattr
(
new_info
,
attr
,
attr_val
)
# finally, use the MAGIC_VARIABLE_MAPPING dictionary to update this
# finally, use the MAGIC_VARIABLE_MAPPING dictionary to update this
# connection info object with 'magic' variables from inventory
# connection info object with 'magic' variables from the variable list
variables
=
host
.
get_vars
()
for
(
attr
,
variable_names
)
in
MAGIC_VARIABLE_MAPPING
.
iteritems
():
for
(
attr
,
variable_names
)
in
MAGIC_VARIABLE_MAPPING
.
iteritems
():
for
variable_name
in
variable_names
:
for
variable_name
in
variable_names
:
if
variable_name
in
variables
:
if
variable_name
in
variables
:
...
@@ -388,18 +370,6 @@ class PlayContext(Base):
...
@@ -388,18 +370,6 @@ class PlayContext(Base):
return
cmd
return
cmd
#def _get_fields(self):
# return [i for i in self.__dict__.keys() if i[:1] != '_']
#def post_validate(self, templar):
# '''
# Finalizes templated values which may be set on this objects fields.
# '''
#
# for field in self._get_fields():
# value = templar.template(getattr(self, field))
# setattr(self, field, value)
def
update_vars
(
self
,
variables
):
def
update_vars
(
self
,
variables
):
'''
'''
Adds 'magic' variables relating to connections to the variable dictionary provided.
Adds 'magic' variables relating to connections to the variable dictionary provided.
...
...
test/units/playbook/test_play_context.py
View file @
42cfacf8
...
@@ -93,14 +93,13 @@ class TestPlayContext(unittest.TestCase):
...
@@ -93,14 +93,13 @@ class TestPlayContext(unittest.TestCase):
mock_task
.
become_pass
=
'mocktaskpass'
mock_task
.
become_pass
=
'mocktaskpass'
mock_task
.
no_log
=
False
mock_task
.
no_log
=
False
mock_host
=
MagicMock
()
all_vars
=
dict
(
mock_host
.
get_vars
.
return_value
=
dict
(
ansible_connection
=
'mock_inventory'
,
ansible_connection
=
'mock_inventory'
,
ansible_ssh_port
=
4321
,
ansible_ssh_port
=
4321
,
)
)
play_context
=
PlayContext
(
play
=
mock_play
,
options
=
options
)
play_context
=
PlayContext
(
play
=
mock_play
,
options
=
options
)
play_context
=
play_context
.
set_task_and_
host_override
(
task
=
mock_task
,
host
=
mock_host
)
play_context
=
play_context
.
set_task_and_
variable_override
(
task
=
mock_task
,
variables
=
all_vars
)
self
.
assertEqual
(
play_context
.
connection
,
'mock_inventory'
)
self
.
assertEqual
(
play_context
.
connection
,
'mock_inventory'
)
self
.
assertEqual
(
play_context
.
remote_user
,
'mocktask'
)
self
.
assertEqual
(
play_context
.
remote_user
,
'mocktask'
)
self
.
assertEqual
(
play_context
.
port
,
4321
)
self
.
assertEqual
(
play_context
.
port
,
4321
)
...
...
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