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

ansible_failed_task is undefined in the rescue section if an error is thrown from a loop task #74303

Closed
ghost opened this issue Apr 15, 2021 · 2 comments
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@ghost
Copy link

ghost commented Apr 15, 2021

Summary

Referencing:

This fix #73881 does not fix those above.

Issue Type

Bug Report

Component Name

block

Ansible Version

$ ansible --version
ansible 2.9.20
  config file = ansible.cfg
  configured module search path = [u'/home/ansible/ansible/modules']
  ansible python module location = /home/ansible/.local/lib/python2.7/site-packages/ansible
  executable location = /home/ansible/.local/bin/ansible
  python version = 2.7.12 (default, Mar  1 2021, 11:38:31) [GCC 5.4.0 20160609]

Configuration

$ ansible-config dump --only-changed

OS / Environment

Ubuntu 16.04.5 LTS (Xenial Xerus)

Steps to Reproduce

- hosts: localhost
  gather_facts: no
  vars:
    ansible_connection: local
    data:
      - name: a1
      - name: a2
      - name: a3

  tasks:
    - debug:
        msg: "{{ data }}"
    - name: Block START
      block:
      - name: LOOP TASK
        debug:
          msg: "The element is: {{ item.name }}"
        loop: "{{ data }}"
        failed_when: item.name is defined

      rescue:
        - name: print ansible_failed_task
          debug:
            var: ansible_failed_task

        - name: print ansible_failed_result
          debug:
            var: ansible_failed_result

Expected Results

ansible_failed_task is defined

Actual Results

PLAY [localhost] **********************************************************************************

TASK [debug] **************************************************************************************
Thursday 15 April 2021  20:10:07 +0000 (0:00:03.476)       0:00:03.476 ******** 
ok: [localhost] => {
    "msg": [
        {
            "name": "a1"
        }, 
        {
            "name": "a2"
        }, 
        {
            "name": "a3"
        }
    ]
}

TASK [LOOP TASK] **********************************************************************************
Thursday 15 April 2021  20:10:07 +0000 (0:00:00.037)       0:00:03.513 ******** 
failed: [localhost] (item={u'name': u'a1'}) => {
    "msg": "The element is: a1"
}
failed: [localhost] (item={u'name': u'a2'}) => {
    "msg": "The element is: a2"
}
failed: [localhost] (item={u'name': u'a3'}) => {
    "msg": "The element is: a3"
}
fatal: [localhost]: FAILED! => {"msg": "All items completed"}

TASK [print ansible_failed_task] ******************************************************************
Thursday 15 April 2021  20:10:07 +0000 (0:00:00.049)       0:00:03.563 ******** 
ok: [localhost] => {
    "ansible_failed_task": "VARIABLE IS NOT DEFINED!"
}

TASK [print ansible_failed_result] ****************************************************************
Thursday 15 April 2021  20:10:07 +0000 (0:00:00.034)       0:00:03.598 ******** 
ok: [localhost] => {
    "ansible_failed_result": {
        "changed": false, 
        "failed": true, 
        "msg": "All items completed", 
        "results": [
            {
                "ansible_loop_var": "item", 
                "changed": false, 
                "failed": true, 
                "failed_when_result": true, 
                "item": {
                    "name": "a1"
                }, 
                "msg": "The element is: a1"
            }, 
            {
                "ansible_loop_var": "item", 
                "changed": false, 
                "failed": true, 
                "failed_when_result": true, 
                "item": {
                    "name": "a2"
                }, 
                "msg": "The element is: a2"
            }, 
            {
                "ansible_loop_var": "item", 
                "changed": false, 
                "failed": true, 
                "failed_when_result": true, 
                "item": {
                    "name": "a3"
                }, 
                "msg": "The element is: a3"
            }
        ]
    }
}

Code of Conduct

I agree to follow the Ansible Code of Conduct

@sivel
Copy link
Member

sivel commented Apr 15, 2021

This was literally fixed minutes ago in #74290

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 15, 2021
@ghost
Copy link
Author

ghost commented Apr 15, 2021

Indeed. Just applied the patch and tested in few real world cases. Everything is working now. Thanks. Closing this one.

@ghost ghost closed this as completed Apr 15, 2021
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Apr 16, 2021
@ansible ansible locked and limited conversation to collaborators May 13, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

3 participants