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

Debug task is run even though dependent task is skipped #13161

Closed
agaffney opened this issue Nov 13, 2015 · 7 comments
Closed

Debug task is run even though dependent task is skipped #13161

agaffney opened this issue Nov 13, 2015 · 7 comments
Labels
bug This issue/PR relates to a bug.

Comments

@agaffney
Copy link
Contributor

I found a case in ansible 1.9.4 (also present in 1.9.2) where a debug task with when: whatever|success runs even though the task that registers whatever was skipped.

I was able to reproduce with this playbook:

- hosts: all
  user: cloud-user

  tasks:
    - name: command that always fails
      shell: /bin/false
      ignore_errors: yes
      register: false_command

    - name: dummy git task
      git: accept_hostkey=yes
      when: false_command|success
      register: dummy_git

    - name: dummy debug
      debug:
        msg: "This should never happen"
      when: dummy_git|success

which results in the following output:

$ ansible-playbook -i 10.60.3.31, ansible_problem.yml 

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [10.60.3.31]

TASK: [command that always fails] ********************************************* 
failed: [10.60.3.31] => {"changed": true, "cmd": "/bin/false", "delta": "0:00:00.002888", "end": "2015-11-13 11:26:25.460150", "rc": 1, "start": "2015-11-13 11:26:25.457262", "warnings": []}
...ignoring

TASK: [dummy git task] ******************************************************** 
skipping: [10.60.3.31]

TASK: [dummy debug] *********************************************************** 
ok: [10.60.3.31] => {
    "msg": "This should never happen"
}

PLAY RECAP ******************************************************************** 
10.60.3.31                 : ok=3    changed=1    unreachable=0    failed=0   
@agaffney
Copy link
Contributor Author

I think I see the problem. The 'success' filter uses the 'failed' filter, which explicitly looks for 'rc' or 'failed' fields, and otherwise assumes success. The "empty" dict from a skipped resource has neither, so is considered successful.

@agaffney
Copy link
Contributor Author

I also tried changing the when clause on the debug task to the following with the same result:

when: dummy_git is defined

The next attempt that checks for a specific field inside the registered variable actually seemed to work:

when: dummy_git.after is defined

@bcoca
Copy link
Member

bcoca commented Nov 13, 2015

discussing in core if we should switch success to be 'not failed and not skipped'

@bcoca
Copy link
Member

bcoca commented Nov 13, 2015

if you want to test the possible patch:

diff --git a/lib/ansible/plugins/test/core.py b/lib/ansible/plugins/test/core.py
index 1bd7892..06fa687 100644
--- a/lib/ansible/plugins/test/core.py
+++ b/lib/ansible/plugins/test/core.py
@@ -36,7 +36,7 @@ def failed(*a, **kw):

 def success(*a, **kw):
     ''' Test if task result yields success '''
-    return not failed(*a, **kw)
+    return not failed(*a, **kw) and not skipped(*a, **kw)

 def changed(*a, **kw):
     ''' Test if task result yields changed '''

@agaffney
Copy link
Contributor Author

That patch results in the debug task being skipped (as expected) with when: dummy_git|success

@bcoca bcoca closed this as completed in 300ee22 Nov 13, 2015
@bcoca
Copy link
Member

bcoca commented Nov 13, 2015

also backported fix to stable-1.9, jic there ever is a 1.9.5

@resmo
Copy link
Contributor

resmo commented Nov 15, 2015

also see PR #8907 and issue #8753

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants