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
02e73850
Commit
02e73850
authored
Apr 15, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter tasks based on tags during iterator setup in v2
parent
96a7d85b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
7 deletions
+52
-7
v2/ansible/executor/play_iterator.py
+7
-2
v2/ansible/executor/task_queue_manager.py
+1
-1
v2/ansible/playbook/block.py
+22
-0
v2/ansible/plugins/strategies/linear.py
+0
-4
v2/samples/test_tags.yml
+22
-0
No files found.
v2/ansible/executor/play_iterator.py
View file @
02e73850
...
...
@@ -87,10 +87,15 @@ class PlayIterator:
FAILED_RESCUE
=
4
FAILED_ALWAYS
=
8
def
__init__
(
self
,
inventory
,
play
):
def
__init__
(
self
,
inventory
,
play
,
connection_info
,
all_vars
):
self
.
_play
=
play
self
.
_blocks
=
self
.
_play
.
compile
()
self
.
_blocks
=
[]
for
block
in
self
.
_play
.
compile
():
new_block
=
block
.
filter_tagged_tasks
(
connection_info
,
all_vars
)
if
new_block
.
has_tasks
():
self
.
_blocks
.
append
(
new_block
)
self
.
_host_states
=
{}
for
host
in
inventory
.
get_hosts
(
self
.
_play
.
hosts
):
self
.
_host_states
[
host
.
name
]
=
HostState
(
blocks
=
self
.
_blocks
)
...
...
v2/ansible/executor/task_queue_manager.py
View file @
02e73850
...
...
@@ -161,7 +161,7 @@ class TaskQueueManager:
raise
AnsibleError
(
"Invalid play strategy specified:
%
s"
%
new_play
.
strategy
,
obj
=
play
.
_ds
)
# build the iterator
iterator
=
PlayIterator
(
inventory
=
self
.
_inventory
,
play
=
new_play
)
iterator
=
PlayIterator
(
inventory
=
self
.
_inventory
,
play
=
new_play
,
connection_info
=
connection_info
,
all_vars
=
all_vars
)
# and run the play using the strategy
return
strategy
.
run
(
iterator
,
connection_info
)
...
...
v2/ansible/playbook/block.py
View file @
02e73850
...
...
@@ -281,3 +281,25 @@ class Block(Base, Become, Conditional, Taggable):
return
value
def
filter_tagged_tasks
(
self
,
connection_info
,
all_vars
):
'''
Creates a new block, with task lists filtered based on the tags contained
within the connection_info object.
'''
def
evaluate_and_append_task
(
target
):
tmp_list
=
[]
for
task
in
target
:
if
task
.
evaluate_tags
(
connection_info
.
only_tags
,
connection_info
.
skip_tags
,
all_vars
=
all_vars
):
tmp_list
.
append
(
task
)
return
tmp_list
new_block
=
self
.
copy
()
new_block
.
block
=
evaluate_and_append_task
(
self
.
block
)
new_block
.
rescue
=
evaluate_and_append_task
(
self
.
rescue
)
new_block
.
always
=
evaluate_and_append_task
(
self
.
always
)
return
new_block
def
has_tasks
(
self
):
return
len
(
self
.
block
)
>
0
or
len
(
self
.
rescue
)
>
0
or
len
(
self
.
always
)
>
0
v2/ansible/plugins/strategies/linear.py
View file @
02e73850
...
...
@@ -178,10 +178,6 @@ class StrategyModule(StrategyBase):
debug
(
"'
%
s' skipped because role has already run"
%
task
)
continue
if
not
task
.
evaluate_tags
(
connection_info
.
only_tags
,
connection_info
.
skip_tags
,
task_vars
)
and
task
.
action
!=
'setup'
:
debug
(
"'
%
s' failed tag evaluation"
%
task
)
continue
if
task
.
action
==
'meta'
:
# meta tasks store their args in the _raw_params field of args,
# since they do not use k=v pairs, so get that
...
...
v2/samples/test_tags.yml
0 → 100644
View file @
02e73850
-
hosts
:
localhost
gather_facts
:
no
tasks
:
-
block
:
-
debug
:
msg="this is the tagged block"
tags
:
-
block
-
block
:
-
debug
:
msg="tagged debug from second block"
tags
:
-
tag1
-
fail
:
tags
:
-
tag1
rescue
:
-
debug
:
msg="tagged rescue from second block"
tags
:
-
rescue_tag
always
:
-
debug
:
msg="tagged always from second block"
tags
:
-
always_tag
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