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
2755602d
Commit
2755602d
authored
Aug 25, 2012
by
Mark Theunissen
Committed by
Michael DeHaan
Aug 27, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check to make sure that tags passed as parameters actually exist
parent
dde97906
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
18 deletions
+40
-18
lib/ansible/playbook/__init__.py
+24
-5
lib/ansible/playbook/play.py
+16
-13
No files found.
lib/ansible/playbook/__init__.py
View file @
2755602d
...
...
@@ -146,12 +146,34 @@ class PlayBook(object):
def
run
(
self
):
''' run all patterns in the playbook '''
plays
=
[]
matched_tags_all
=
set
()
unmatched_tags_all
=
set
()
# loop through all patterns and run them
self
.
callbacks
.
on_start
()
for
play_ds
in
self
.
playbook
:
play
=
Play
(
self
,
play_ds
)
matched_tags
,
unmatched_tags
=
play
.
compare_tags
(
self
.
only_tags
)
matched_tags_all
=
matched_tags_all
|
matched_tags
unmatched_tags_all
=
unmatched_tags_all
|
unmatched_tags
# if we have matched_tags, the play must be run.
# if the play contains no tasks, assume we just want to gather facts
if
(
len
(
matched_tags
)
>
0
or
len
(
play
.
tasks
())
==
0
):
plays
.
append
(
play
)
# if the playbook is invoked with --tags that don't exist at all in the playbooks
# then we need to raise an error so that the user can correct the arguments.
unknown_tags
=
set
(
self
.
only_tags
)
-
(
matched_tags_all
|
unmatched_tags_all
)
if
len
(
unknown_tags
)
>
0
:
unmatched_tags_all
.
discard
(
'all'
)
msg
=
'tags "
%
s" given as argument but not found in playbooks, did you mean one of "
%
s"?'
raise
errors
.
AnsibleError
(
msg
%
(
', '
.
join
(
unknown_tags
),
', '
.
join
(
unmatched_tags_all
)))
for
play
in
plays
:
self
.
_run_play
(
play
)
# summarize the results
results
=
{}
for
host
in
self
.
stats
.
processed
.
keys
():
...
...
@@ -292,9 +314,6 @@ class PlayBook(object):
def
_run_play
(
self
,
play
):
''' run a list of tasks for a given pattern, in order '''
if
not
play
.
should_run
(
self
.
only_tags
):
return
self
.
callbacks
.
on_play_start
(
play
.
name
)
# get facts from system
...
...
@@ -315,7 +334,7 @@ class PlayBook(object):
for
x
in
range
(
play
.
serial
):
if
len
(
all_hosts
)
>
0
:
play_hosts
.
append
(
all_hosts
.
pop
())
serialized_batch
.
append
(
play_hosts
)
serialized_batch
.
append
(
play_hosts
)
for
on_hosts
in
serialized_batch
:
...
...
@@ -338,6 +357,6 @@ class PlayBook(object):
self
.
inventory
.
restrict_to
(
handler
.
notified_by
)
self
.
_run_task
(
play
,
handler
,
True
)
self
.
inventory
.
lift_restriction
()
self
.
inventory
.
lift_also_restriction
()
lib/ansible/playbook/play.py
View file @
2755602d
...
...
@@ -130,7 +130,7 @@ class Play(object):
return
self
.
_tasks
def
handlers
(
self
):
''' return handler objects for this play '''
''' return handler objects for this play '''
return
self
.
_handlers
# *************************************************
...
...
@@ -197,22 +197,25 @@ class Play(object):
# *************************************************
def
should_run
(
self
,
tags
):
''' does the play match any of the tags? '''
def
compare_tags
(
self
,
tags
):
''' given a list of tags that the user has specified, return two lists:
matched_tags: tags were found within the current play and match those given
by the user
unmatched_tags: tags that were found within the current play but do not match
any provided by the user '''
tags_counted
=
0
# gather all the tags in all the tasks into one list
all_tags
=
[]
for
task
in
self
.
_tasks
:
for
task_tag
in
task
.
tags
:
tags_counted
=
tags_counted
+
1
if
task_tag
in
tags
:
return
True
all_tags
.
extend
(
task
.
tags
)
if
tags_counted
>
0
:
return
False
# compare the lists of tags using sets and return the matched and unmatched
all_tags_set
=
set
(
all_tags
)
tags_set
=
set
(
tags
)
matched_tags
=
all_tags_set
&
tags_set
unmatched_tags
=
all_tags_set
-
tags_set
# didn't tag the play, and the play contains no steps
# so assume we just want to gather facts
return
True
return
matched_tags
,
unmatched_tags
# *************************************************
...
...
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