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
601a1cc6
Commit
601a1cc6
authored
Aug 25, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Multiple fixes for include statements and blocks in general
Fixes #11981 Fixes #11995 Fixes #12039 Fixes #12077
parent
9f9891df
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
167 additions
and
79 deletions
+167
-79
lib/ansible/executor/play_iterator.py
+128
-60
lib/ansible/playbook/block.py
+9
-5
lib/ansible/playbook/task.py
+1
-1
lib/ansible/plugins/strategies/linear.py
+28
-6
samples/test_block.yml
+0
-1
test/integration/roles/test_includes/tasks/main.yml
+1
-6
No files found.
lib/ansible/executor/play_iterator.py
View file @
601a1cc6
...
@@ -31,6 +31,13 @@ from ansible.utils.boolean import boolean
...
@@ -31,6 +31,13 @@ from ansible.utils.boolean import boolean
__all__
=
[
'PlayIterator'
]
__all__
=
[
'PlayIterator'
]
try
:
from
__main__
import
display
except
ImportError
:
from
ansible.utils.display
import
Display
display
=
Display
()
class
HostState
:
class
HostState
:
def
__init__
(
self
,
blocks
):
def
__init__
(
self
,
blocks
):
self
.
_blocks
=
blocks
[:]
self
.
_blocks
=
blocks
[:]
...
@@ -43,10 +50,12 @@ class HostState:
...
@@ -43,10 +50,12 @@ class HostState:
self
.
run_state
=
PlayIterator
.
ITERATING_SETUP
self
.
run_state
=
PlayIterator
.
ITERATING_SETUP
self
.
fail_state
=
PlayIterator
.
FAILED_NONE
self
.
fail_state
=
PlayIterator
.
FAILED_NONE
self
.
pending_setup
=
False
self
.
pending_setup
=
False
self
.
child_state
=
None
self
.
tasks_child_state
=
None
self
.
rescue_child_state
=
None
self
.
always_child_state
=
None
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"HOST STATE: block=
%
d, task=
%
d, rescue=
%
d, always=
%
d, role=
%
s, run_state=
%
d, fail_state=
%
d, pending_setup=
%
s, child state?
%
s"
%
(
return
"HOST STATE: block=
%
d, task=
%
d, rescue=
%
d, always=
%
d, role=
%
s, run_state=
%
d, fail_state=
%
d, pending_setup=
%
s,
tasks child state?
%
s, rescue child state?
%
s, always
child state?
%
s"
%
(
self
.
cur_block
,
self
.
cur_block
,
self
.
cur_regular_task
,
self
.
cur_regular_task
,
self
.
cur_rescue_task
,
self
.
cur_rescue_task
,
...
@@ -55,7 +64,9 @@ class HostState:
...
@@ -55,7 +64,9 @@ class HostState:
self
.
run_state
,
self
.
run_state
,
self
.
fail_state
,
self
.
fail_state
,
self
.
pending_setup
,
self
.
pending_setup
,
self
.
child_state
,
self
.
tasks_child_state
,
self
.
rescue_child_state
,
self
.
always_child_state
,
)
)
def
get_current_block
(
self
):
def
get_current_block
(
self
):
...
@@ -71,7 +82,12 @@ class HostState:
...
@@ -71,7 +82,12 @@ class HostState:
new_state
.
run_state
=
self
.
run_state
new_state
.
run_state
=
self
.
run_state
new_state
.
fail_state
=
self
.
fail_state
new_state
.
fail_state
=
self
.
fail_state
new_state
.
pending_setup
=
self
.
pending_setup
new_state
.
pending_setup
=
self
.
pending_setup
new_state
.
child_state
=
self
.
child_state
if
self
.
tasks_child_state
is
not
None
:
new_state
.
tasks_child_state
=
self
.
tasks_child_state
.
copy
()
if
self
.
rescue_child_state
is
not
None
:
new_state
.
rescue_child_state
=
self
.
rescue_child_state
.
copy
()
if
self
.
always_child_state
is
not
None
:
new_state
.
always_child_state
=
self
.
always_child_state
.
copy
()
return
new_state
return
new_state
class
PlayIterator
:
class
PlayIterator
:
...
@@ -126,10 +142,12 @@ class PlayIterator:
...
@@ -126,10 +142,12 @@ class PlayIterator:
def
get_next_task_for_host
(
self
,
host
,
peek
=
False
):
def
get_next_task_for_host
(
self
,
host
,
peek
=
False
):
display
.
debug
(
"getting the next task for host
%
s"
%
host
.
name
)
s
=
self
.
get_host_state
(
host
)
s
=
self
.
get_host_state
(
host
)
task
=
None
task
=
None
if
s
.
run_state
==
self
.
ITERATING_COMPLETE
:
if
s
.
run_state
==
self
.
ITERATING_COMPLETE
:
display
.
debug
(
"host
%
s is done iterating, returning"
%
host
.
name
)
return
(
None
,
None
)
return
(
None
,
None
)
elif
s
.
run_state
==
self
.
ITERATING_SETUP
:
elif
s
.
run_state
==
self
.
ITERATING_SETUP
:
s
.
run_state
=
self
.
ITERATING_TASKS
s
.
run_state
=
self
.
ITERATING_TASKS
...
@@ -169,6 +187,9 @@ class PlayIterator:
...
@@ -169,6 +187,9 @@ class PlayIterator:
if
not
peek
:
if
not
peek
:
self
.
_host_states
[
host
.
name
]
=
s
self
.
_host_states
[
host
.
name
]
=
s
display
.
debug
(
"done getting next task for host
%
s"
%
host
.
name
)
display
.
debug
(
" ^ task is:
%
s"
%
task
)
display
.
debug
(
" ^ state is:
%
s"
%
s
)
return
(
s
,
task
)
return
(
s
,
task
)
...
@@ -176,15 +197,6 @@ class PlayIterator:
...
@@ -176,15 +197,6 @@ class PlayIterator:
task
=
None
task
=
None
# if we previously encountered a child block and we have a
# saved child state, try and get the next task from there
if
state
.
child_state
:
(
state
.
child_state
,
task
)
=
self
.
_get_next_task_from_state
(
state
.
child_state
,
peek
=
peek
)
if
task
:
return
(
state
.
child_state
,
task
)
else
:
state
.
child_state
=
None
# try and find the next task, given the current state.
# try and find the next task, given the current state.
while
True
:
while
True
:
# try to get the current block from the list of blocks, and
# try to get the current block from the list of blocks, and
...
@@ -207,6 +219,18 @@ class PlayIterator:
...
@@ -207,6 +219,18 @@ class PlayIterator:
state
.
run_state
=
self
.
ITERATING_ALWAYS
state
.
run_state
=
self
.
ITERATING_ALWAYS
else
:
else
:
task
=
block
.
block
[
state
.
cur_regular_task
]
task
=
block
.
block
[
state
.
cur_regular_task
]
# if the current task is actually a child block, we dive into it
if
isinstance
(
task
,
Block
)
or
state
.
tasks_child_state
is
not
None
:
if
state
.
tasks_child_state
is
None
:
state
.
tasks_child_state
=
HostState
(
blocks
=
[
task
])
state
.
tasks_child_state
.
run_state
=
self
.
ITERATING_TASKS
state
.
tasks_child_state
.
cur_role
=
state
.
cur_role
(
state
.
tasks_child_state
,
task
)
=
self
.
_get_next_task_from_state
(
state
.
tasks_child_state
,
peek
=
peek
)
if
task
is
None
:
state
.
tasks_child_state
=
None
state
.
cur_regular_task
+=
1
continue
else
:
state
.
cur_regular_task
+=
1
state
.
cur_regular_task
+=
1
elif
state
.
run_state
==
self
.
ITERATING_RESCUE
:
elif
state
.
run_state
==
self
.
ITERATING_RESCUE
:
...
@@ -218,6 +242,17 @@ class PlayIterator:
...
@@ -218,6 +242,17 @@ class PlayIterator:
state
.
run_state
=
self
.
ITERATING_ALWAYS
state
.
run_state
=
self
.
ITERATING_ALWAYS
else
:
else
:
task
=
block
.
rescue
[
state
.
cur_rescue_task
]
task
=
block
.
rescue
[
state
.
cur_rescue_task
]
if
isinstance
(
task
,
Block
)
or
state
.
rescue_child_state
is
not
None
:
if
state
.
rescue_child_state
is
None
:
state
.
rescue_child_state
=
HostState
(
blocks
=
[
task
])
state
.
rescue_child_state
.
run_state
=
self
.
ITERATING_TASKS
state
.
rescue_child_state
.
cur_role
=
state
.
cur_role
(
state
.
rescue_child_state
,
task
)
=
self
.
_get_next_task_from_state
(
state
.
rescue_child_state
,
peek
=
peek
)
if
task
is
None
:
state
.
rescue_child_state
=
None
state
.
cur_rescue_task
+=
1
continue
else
:
state
.
cur_rescue_task
+=
1
state
.
cur_rescue_task
+=
1
elif
state
.
run_state
==
self
.
ITERATING_ALWAYS
:
elif
state
.
run_state
==
self
.
ITERATING_ALWAYS
:
...
@@ -233,38 +268,55 @@ class PlayIterator:
...
@@ -233,38 +268,55 @@ class PlayIterator:
state
.
child_state
=
None
state
.
child_state
=
None
else
:
else
:
task
=
block
.
always
[
state
.
cur_always_task
]
task
=
block
.
always
[
state
.
cur_always_task
]
if
isinstance
(
task
,
Block
)
or
state
.
always_child_state
is
not
None
:
if
state
.
always_child_state
is
None
:
state
.
always_child_state
=
HostState
(
blocks
=
[
task
])
state
.
always_child_state
.
run_state
=
self
.
ITERATING_TASKS
state
.
always_child_state
.
cur_role
=
state
.
cur_role
(
state
.
always_child_state
,
task
)
=
self
.
_get_next_task_from_state
(
state
.
always_child_state
,
peek
=
peek
)
if
task
is
None
:
state
.
always_child_state
=
None
state
.
cur_always_task
+=
1
continue
else
:
state
.
cur_always_task
+=
1
state
.
cur_always_task
+=
1
elif
state
.
run_state
==
self
.
ITERATING_COMPLETE
:
elif
state
.
run_state
==
self
.
ITERATING_COMPLETE
:
return
(
state
,
None
)
return
(
state
,
None
)
# if the current task is actually a child block, we dive into it
if
isinstance
(
task
,
Block
):
state
.
child_state
=
HostState
(
blocks
=
[
task
])
state
.
child_state
.
run_state
=
self
.
ITERATING_TASKS
state
.
child_state
.
cur_role
=
state
.
cur_role
(
state
.
child_state
,
task
)
=
self
.
_get_next_task_from_state
(
state
.
child_state
,
peek
=
peek
)
# if something above set the task, break out of the loop now
# if something above set the task, break out of the loop now
if
task
:
if
task
:
break
break
return
(
state
,
task
)
return
(
state
,
task
)
def
_set_failed_state
(
self
,
state
):
if
state
.
pending_setup
:
state
.
fail_state
|=
self
.
FAILED_SETUP
state
.
run_state
=
self
.
ITERATING_COMPLETE
elif
state
.
run_state
==
self
.
ITERATING_TASKS
:
if
state
.
tasks_child_state
is
not
None
:
state
.
tasks_child_state
=
self
.
_set_failed_state
(
state
.
tasks_child_state
)
else
:
state
.
fail_state
|=
self
.
FAILED_TASKS
state
.
run_state
=
self
.
ITERATING_RESCUE
elif
state
.
run_state
==
self
.
ITERATING_RESCUE
:
if
state
.
rescue_child_state
is
not
None
:
state
.
rescue_child_state
=
self
.
_set_failed_state
(
state
.
rescue_child_state
)
else
:
state
.
fail_state
|=
self
.
FAILED_RESCUE
state
.
run_state
=
self
.
ITERATING_ALWAYS
elif
state
.
run_state
==
self
.
ITERATING_ALWAYS
:
if
state
.
always_child_state
is
not
None
:
state
.
always_child_state
=
self
.
_set_failed_state
(
state
.
always_child_state
)
else
:
state
.
fail_state
|=
self
.
FAILED_ALWAYS
state
.
run_state
=
self
.
ITERATING_COMPLETE
return
state
def
mark_host_failed
(
self
,
host
):
def
mark_host_failed
(
self
,
host
):
s
=
self
.
get_host_state
(
host
)
s
=
self
.
get_host_state
(
host
)
if
s
.
pending_setup
:
s
=
self
.
_set_failed_state
(
s
)
s
.
fail_state
|=
self
.
FAILED_SETUP
s
.
run_state
=
self
.
ITERATING_COMPLETE
elif
s
.
run_state
==
self
.
ITERATING_TASKS
:
s
.
fail_state
|=
self
.
FAILED_TASKS
s
.
run_state
=
self
.
ITERATING_RESCUE
elif
s
.
run_state
==
self
.
ITERATING_RESCUE
:
s
.
fail_state
|=
self
.
FAILED_RESCUE
s
.
run_state
=
self
.
ITERATING_ALWAYS
elif
s
.
run_state
==
self
.
ITERATING_ALWAYS
:
s
.
fail_state
|=
self
.
FAILED_ALWAYS
s
.
run_state
=
self
.
ITERATING_COMPLETE
self
.
_host_states
[
host
.
name
]
=
s
self
.
_host_states
[
host
.
name
]
=
s
def
get_failed_hosts
(
self
):
def
get_failed_hosts
(
self
):
...
@@ -278,32 +330,35 @@ class PlayIterator:
...
@@ -278,32 +330,35 @@ class PlayIterator:
allows us to find the original task passed into the executor engine.
allows us to find the original task passed into the executor engine.
'''
'''
def
_search_block
(
block
,
task
):
def
_search_block
(
block
,
task
):
for
t
in
block
.
block
:
'''
helper method to check a block's task lists (block/rescue/always)
for a given task uuid. If a Block is encountered in the place of a
task, it will be recursively searched (this happens when a task
include inserts one or more blocks into a task list).
'''
for
b
in
(
block
.
block
,
block
.
rescue
,
block
.
always
):
for
t
in
b
:
if
isinstance
(
t
,
Block
):
if
isinstance
(
t
,
Block
):
res
=
_search_block
(
t
,
task
)
res
=
_search_block
(
t
,
task
)
if
res
:
if
res
:
return
res
return
res
elif
t
.
_uuid
==
task
.
_uuid
:
elif
t
.
_uuid
==
task
.
_uuid
:
return
t
return
t
for
t
in
block
.
rescue
:
return
None
if
isinstance
(
t
,
Block
):
res
=
_search_block
(
t
,
task
)
def
_search_state
(
state
,
task
):
for
block
in
state
.
_blocks
:
res
=
_search_block
(
block
,
task
)
if
res
:
if
res
:
return
res
return
res
elif
t
.
_uuid
==
task
.
_uuid
:
for
child_state
in
(
state
.
tasks_child_state
,
state
.
rescue_child_state
,
state
.
always_child_state
):
return
t
res
=
_search_state
(
child_state
,
task
)
for
t
in
block
.
always
:
if
isinstance
(
t
,
Block
):
res
=
_search_block
(
t
,
task
)
if
res
:
if
res
:
return
res
return
res
elif
t
.
_uuid
==
task
.
_uuid
:
return
t
return
None
return
None
s
=
self
.
get_host_state
(
host
)
s
=
self
.
get_host_state
(
host
)
for
block
in
s
.
_blocks
:
res
=
_search_state
(
s
,
task
)
res
=
_search_block
(
block
,
task
)
if
res
:
if
res
:
return
res
return
res
...
@@ -314,23 +369,36 @@ class PlayIterator:
...
@@ -314,23 +369,36 @@ class PlayIterator:
return
None
return
None
def
add_tasks
(
self
,
host
,
task_list
):
def
_insert_tasks_into_state
(
self
,
state
,
task_list
):
s
=
self
.
get_host_state
(
host
)
if
state
.
run_state
==
self
.
ITERATING_TASKS
:
target_block
=
s
.
_blocks
[
s
.
cur_block
]
.
copy
(
exclude_parent
=
True
)
if
state
.
tasks_child_state
:
state
.
tasks_child_state
=
self
.
_insert_tasks_into_state
(
state
.
tasks_child_state
,
task_list
)
if
s
.
run_state
==
self
.
ITERATING_TASKS
:
else
:
before
=
target_block
.
block
[:
s
.
cur_regular_task
]
target_block
=
state
.
_blocks
[
state
.
cur_block
]
.
copy
(
exclude_parent
=
True
)
after
=
target_block
.
block
[
s
.
cur_regular_task
:]
before
=
target_block
.
block
[:
state
.
cur_regular_task
]
after
=
target_block
.
block
[
state
.
cur_regular_task
:]
target_block
.
block
=
before
+
task_list
+
after
target_block
.
block
=
before
+
task_list
+
after
elif
s
.
run_state
==
self
.
ITERATING_RESCUE
:
state
.
_blocks
[
state
.
cur_block
]
=
target_block
before
=
target_block
.
rescue
[:
s
.
cur_rescue_task
]
elif
state
.
run_state
==
self
.
ITERATING_RESCUE
:
after
=
target_block
.
rescue
[
s
.
cur_rescue_task
:]
if
state
.
rescue_child_state
:
state
.
rescue_child_state
=
self
.
_insert_tasks_into_state
(
state
.
rescue_child_state
,
task_list
)
else
:
target_block
=
state
.
_blocks
[
state
.
cur_block
]
.
copy
(
exclude_parent
=
True
)
before
=
target_block
.
rescue
[:
state
.
cur_rescue_task
]
after
=
target_block
.
rescue
[
state
.
cur_rescue_task
:]
target_block
.
rescue
=
before
+
task_list
+
after
target_block
.
rescue
=
before
+
task_list
+
after
elif
s
.
run_state
==
self
.
ITERATING_ALWAYS
:
state
.
_blocks
[
state
.
cur_block
]
=
target_block
before
=
target_block
.
always
[:
s
.
cur_always_task
]
elif
state
.
run_state
==
self
.
ITERATING_ALWAYS
:
after
=
target_block
.
always
[
s
.
cur_always_task
:]
if
state
.
always_child_state
:
state
.
always_child_state
=
self
.
_insert_tasks_into_state
(
state
.
always_child_state
,
task_list
)
else
:
target_block
=
state
.
_blocks
[
state
.
cur_block
]
.
copy
(
exclude_parent
=
True
)
before
=
target_block
.
always
[:
state
.
cur_always_task
]
after
=
target_block
.
always
[
state
.
cur_always_task
:]
target_block
.
always
=
before
+
task_list
+
after
target_block
.
always
=
before
+
task_list
+
after
state
.
_blocks
[
state
.
cur_block
]
=
target_block
return
state
s
.
_blocks
[
s
.
cur_block
]
=
target_block
def
add_tasks
(
self
,
host
,
task_list
):
self
.
_host_states
[
host
.
name
]
=
s
self
.
_host_states
[
host
.
name
]
=
s
elf
.
_insert_tasks_into_state
(
self
.
get_host_state
(
host
),
task_list
)
lib/ansible/playbook/block.py
View file @
601a1cc6
...
@@ -325,16 +325,20 @@ class Block(Base, Become, Conditional, Taggable):
...
@@ -325,16 +325,20 @@ class Block(Base, Become, Conditional, Taggable):
def
evaluate_and_append_task
(
target
):
def
evaluate_and_append_task
(
target
):
tmp_list
=
[]
tmp_list
=
[]
for
task
in
target
:
for
task
in
target
:
if
task
.
action
in
(
'meta'
,
'include'
)
or
task
.
evaluate_tags
(
play_context
.
only_tags
,
play_context
.
skip_tags
,
all_vars
=
all_vars
):
if
isinstance
(
task
,
Block
):
tmp_list
.
append
(
evaluate_block
(
task
))
elif
task
.
action
in
(
'meta'
,
'include'
)
or
task
.
evaluate_tags
(
play_context
.
only_tags
,
play_context
.
skip_tags
,
all_vars
=
all_vars
):
tmp_list
.
append
(
task
)
tmp_list
.
append
(
task
)
return
tmp_list
return
tmp_list
def
evaluate_block
(
block
):
new_block
=
self
.
copy
()
new_block
=
self
.
copy
()
new_block
.
block
=
evaluate_and_append_task
(
self
.
block
)
new_block
.
block
=
evaluate_and_append_task
(
block
.
block
)
new_block
.
rescue
=
evaluate_and_append_task
(
self
.
rescue
)
new_block
.
rescue
=
evaluate_and_append_task
(
block
.
rescue
)
new_block
.
always
=
evaluate_and_append_task
(
self
.
always
)
new_block
.
always
=
evaluate_and_append_task
(
block
.
always
)
return
new_block
return
new_block
return
evaluate_block
(
self
)
def
has_tasks
(
self
):
def
has_tasks
(
self
):
return
len
(
self
.
block
)
>
0
or
len
(
self
.
rescue
)
>
0
or
len
(
self
.
always
)
>
0
return
len
(
self
.
block
)
>
0
or
len
(
self
.
rescue
)
>
0
or
len
(
self
.
always
)
>
0
lib/ansible/playbook/task.py
View file @
601a1cc6
...
@@ -256,7 +256,7 @@ class Task(Base, Conditional, Taggable, Become):
...
@@ -256,7 +256,7 @@ class Task(Base, Conditional, Taggable, Become):
new_me
.
_task_include
=
None
new_me
.
_task_include
=
None
if
self
.
_task_include
:
if
self
.
_task_include
:
new_me
.
_task_include
=
self
.
_task_include
.
copy
()
new_me
.
_task_include
=
self
.
_task_include
.
copy
(
exclude_block
=
exclude_block
)
return
new_me
return
new_me
...
...
lib/ansible/plugins/strategies/linear.py
View file @
601a1cc6
...
@@ -28,6 +28,13 @@ from ansible.plugins import action_loader
...
@@ -28,6 +28,13 @@ from ansible.plugins import action_loader
from
ansible.plugins.strategies
import
StrategyBase
from
ansible.plugins.strategies
import
StrategyBase
from
ansible.template
import
Templar
from
ansible.template
import
Templar
try
:
from
__main__
import
display
except
ImportError
:
from
ansible.utils.display
import
Display
display
=
Display
()
class
StrategyModule
(
StrategyBase
):
class
StrategyModule
(
StrategyBase
):
def
_get_next_task_lockstep
(
self
,
hosts
,
iterator
):
def
_get_next_task_lockstep
(
self
,
hosts
,
iterator
):
...
@@ -43,8 +50,10 @@ class StrategyModule(StrategyBase):
...
@@ -43,8 +50,10 @@ class StrategyModule(StrategyBase):
noop_task
.
set_loader
(
iterator
.
_play
.
_loader
)
noop_task
.
set_loader
(
iterator
.
_play
.
_loader
)
host_tasks
=
{}
host_tasks
=
{}
display
.
debug
(
"building list of next tasks for hosts"
)
for
host
in
hosts
:
for
host
in
hosts
:
host_tasks
[
host
.
name
]
=
iterator
.
get_next_task_for_host
(
host
,
peek
=
True
)
host_tasks
[
host
.
name
]
=
iterator
.
get_next_task_for_host
(
host
,
peek
=
True
)
display
.
debug
(
"done building task lists"
)
num_setups
=
0
num_setups
=
0
num_tasks
=
0
num_tasks
=
0
...
@@ -53,6 +62,7 @@ class StrategyModule(StrategyBase):
...
@@ -53,6 +62,7 @@ class StrategyModule(StrategyBase):
lowest_cur_block
=
len
(
iterator
.
_blocks
)
lowest_cur_block
=
len
(
iterator
.
_blocks
)
display
.
debug
(
"counting tasks in each state of execution"
)
for
(
k
,
v
)
in
host_tasks
.
iteritems
():
for
(
k
,
v
)
in
host_tasks
.
iteritems
():
if
v
is
None
:
if
v
is
None
:
continue
continue
...
@@ -72,6 +82,7 @@ class StrategyModule(StrategyBase):
...
@@ -72,6 +82,7 @@ class StrategyModule(StrategyBase):
num_rescue
+=
1
num_rescue
+=
1
elif
s
.
run_state
==
PlayIterator
.
ITERATING_ALWAYS
:
elif
s
.
run_state
==
PlayIterator
.
ITERATING_ALWAYS
:
num_always
+=
1
num_always
+=
1
display
.
debug
(
"done counting tasks in each state of execution"
)
def
_advance_selected_hosts
(
hosts
,
cur_block
,
cur_state
):
def
_advance_selected_hosts
(
hosts
,
cur_block
,
cur_state
):
'''
'''
...
@@ -83,6 +94,7 @@ class StrategyModule(StrategyBase):
...
@@ -83,6 +94,7 @@ class StrategyModule(StrategyBase):
# we return the values in the order they were originally
# we return the values in the order they were originally
# specified in the given hosts array
# specified in the given hosts array
rvals
=
[]
rvals
=
[]
display
.
debug
(
"starting to advance hosts"
)
for
host
in
hosts
:
for
host
in
hosts
:
host_state_task
=
host_tasks
[
host
.
name
]
host_state_task
=
host_tasks
[
host
.
name
]
if
host_state_task
is
None
:
if
host_state_task
is
None
:
...
@@ -92,36 +104,39 @@ class StrategyModule(StrategyBase):
...
@@ -92,36 +104,39 @@ class StrategyModule(StrategyBase):
continue
continue
if
s
.
run_state
==
cur_state
and
s
.
cur_block
==
cur_block
:
if
s
.
run_state
==
cur_state
and
s
.
cur_block
==
cur_block
:
new_t
=
iterator
.
get_next_task_for_host
(
host
)
new_t
=
iterator
.
get_next_task_for_host
(
host
)
#if new_t != t:
# raise AnsibleError("iterator error, wtf?") FIXME
rvals
.
append
((
host
,
t
))
rvals
.
append
((
host
,
t
))
else
:
else
:
rvals
.
append
((
host
,
noop_task
))
rvals
.
append
((
host
,
noop_task
))
display
.
debug
(
"done advancing hosts to next task"
)
return
rvals
return
rvals
# if any hosts are in ITERATING_SETUP, return the setup task
# if any hosts are in ITERATING_SETUP, return the setup task
# while all other hosts get a noop
# while all other hosts get a noop
if
num_setups
:
if
num_setups
:
display
.
debug
(
"advancing hosts in ITERATING_SETUP"
)
return
_advance_selected_hosts
(
hosts
,
lowest_cur_block
,
PlayIterator
.
ITERATING_SETUP
)
return
_advance_selected_hosts
(
hosts
,
lowest_cur_block
,
PlayIterator
.
ITERATING_SETUP
)
# if any hosts are in ITERATING_TASKS, return the next normal
# if any hosts are in ITERATING_TASKS, return the next normal
# task for these hosts, while all other hosts get a noop
# task for these hosts, while all other hosts get a noop
if
num_tasks
:
if
num_tasks
:
display
.
debug
(
"advancing hosts in ITERATING_TASKS"
)
return
_advance_selected_hosts
(
hosts
,
lowest_cur_block
,
PlayIterator
.
ITERATING_TASKS
)
return
_advance_selected_hosts
(
hosts
,
lowest_cur_block
,
PlayIterator
.
ITERATING_TASKS
)
# if any hosts are in ITERATING_RESCUE, return the next rescue
# if any hosts are in ITERATING_RESCUE, return the next rescue
# task for these hosts, while all other hosts get a noop
# task for these hosts, while all other hosts get a noop
if
num_rescue
:
if
num_rescue
:
display
.
debug
(
"advancing hosts in ITERATING_RESCUE"
)
return
_advance_selected_hosts
(
hosts
,
lowest_cur_block
,
PlayIterator
.
ITERATING_RESCUE
)
return
_advance_selected_hosts
(
hosts
,
lowest_cur_block
,
PlayIterator
.
ITERATING_RESCUE
)
# if any hosts are in ITERATING_ALWAYS, return the next always
# if any hosts are in ITERATING_ALWAYS, return the next always
# task for these hosts, while all other hosts get a noop
# task for these hosts, while all other hosts get a noop
if
num_always
:
if
num_always
:
display
.
debug
(
"advancing hosts in ITERATING_ALWAYS"
)
return
_advance_selected_hosts
(
hosts
,
lowest_cur_block
,
PlayIterator
.
ITERATING_ALWAYS
)
return
_advance_selected_hosts
(
hosts
,
lowest_cur_block
,
PlayIterator
.
ITERATING_ALWAYS
)
# at this point, everything must be ITERATING_COMPLETE, so we
# at this point, everything must be ITERATING_COMPLETE, so we
# return None for all hosts in the list
# return None for all hosts in the list
display
.
debug
(
"all hosts are done, so returning None's for all hosts"
)
return
[(
host
,
None
)
for
host
in
hosts
]
return
[(
host
,
None
)
for
host
in
hosts
]
def
run
(
self
,
iterator
,
play_context
):
def
run
(
self
,
iterator
,
play_context
):
...
@@ -200,15 +215,22 @@ class StrategyModule(StrategyBase):
...
@@ -200,15 +215,22 @@ class StrategyModule(StrategyBase):
self
.
_display
.
debug
(
"done getting variables"
)
self
.
_display
.
debug
(
"done getting variables"
)
if
not
callback_sent
:
if
not
callback_sent
:
temp_task
=
task
.
copy
()
display
.
debug
(
"sending task start callback, copying the task so we can template it temporarily"
)
saved_name
=
task
.
name
display
.
debug
(
"done copying, going to template now"
)
try
:
try
:
temp_task
.
name
=
unicode
(
templar
.
template
(
temp_task
.
name
,
fail_on_undefined
=
False
))
task
.
name
=
unicode
(
templar
.
template
(
task
.
name
,
fail_on_undefined
=
False
))
display
.
debug
(
"done templating"
)
except
:
except
:
# just ignore any errors during task name templating,
# just ignore any errors during task name templating,
# we don't care if it just shows the raw name
# we don't care if it just shows the raw name
display
.
debug
(
"templating failed for some reason"
)
pass
pass
self
.
_tqm
.
send_callback
(
'v2_playbook_on_task_start'
,
temp_task
,
is_conditional
=
False
)
display
.
debug
(
"here goes the callback..."
)
self
.
_tqm
.
send_callback
(
'v2_playbook_on_task_start'
,
task
,
is_conditional
=
False
)
task
.
name
=
saved_name
callback_sent
=
True
callback_sent
=
True
display
.
debug
(
"sending task start callback"
)
self
.
_blocked_hosts
[
host
.
get_name
()]
=
True
self
.
_blocked_hosts
[
host
.
get_name
()]
=
True
self
.
_queue_task
(
host
,
task
,
task_vars
,
play_context
)
self
.
_queue_task
(
host
,
task
,
task_vars
,
play_context
)
...
...
samples/test_block.yml
View file @
601a1cc6
-
hosts
:
all
-
hosts
:
all
connection
:
local
gather_facts
:
yes
gather_facts
:
yes
tasks
:
tasks
:
-
block
:
-
block
:
...
...
test/integration/roles/test_includes/tasks/main.yml
View file @
601a1cc6
...
@@ -31,11 +31,6 @@
...
@@ -31,11 +31,6 @@
b
:
102
b
:
102
c
:
103
c
:
103
# Params specified via k=v values are strings, while those
# that come from variables will keep the type they were previously.
# Prior to v2.0, facts too priority over include params, however
# this is no longer the case.
-
include
:
included_task1.yml a={{a}} b={{b}} c=103
-
include
:
included_task1.yml a={{a}} b={{b}} c=103
-
name
:
verify variable include params
-
name
:
verify variable include params
...
@@ -43,7 +38,7 @@
...
@@ -43,7 +38,7 @@
that
:
that
:
-
"
ca
==
101"
-
"
ca
==
101"
-
"
cb
==
102"
-
"
cb
==
102"
-
"
cc
==
'103'
"
-
"
cc
==
103
"
# Test that strings are not turned into numbers
# Test that strings are not turned into numbers
-
set_fact
:
-
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