Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jinja2 filter 'skipped' to test for a registered variable from a ski... #3463

Merged
merged 1 commit into from
Jul 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docsite/latest/rst/playbooks2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ decide to do something conditionally based on success or failure::
when: result|failed
- action: command /bin/something_else
when: result|success
- action: command /bin/still/something_else
when: result|skipped


As a reminder, to see what derived variables are available, you can do::
Expand Down
10 changes: 10 additions & 0 deletions lib/ansible/runner/filter_plugins/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def failed(*a, **kw):
def success(*a, **kw):
return not failed(*a, **kw)

def skipped(*a, **kw):
item = a[0]
if type(item) != dict:
raise errors.AnsibleError("|skipped expects a dictionary")
skipped = item.get('skipped', False)
return skipped

def mandatory(a):
''' Make a variable mandatory '''
if not a:
Expand Down Expand Up @@ -88,6 +95,9 @@ def filters(self):
'failed' : failed,
'success' : success,

# skip testing
'skipped' : skipped,

# variable existence
'mandatory': mandatory,

Expand Down