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

include: fails during exception processing #12876

Closed
larsks opened this issue Oct 22, 2015 · 6 comments · Fixed by #12879
Closed

include: fails during exception processing #12876

larsks opened this issue Oct 22, 2015 · 6 comments · Fixed by #12879
Assignees
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Milestone

Comments

@larsks
Copy link
Contributor

larsks commented Oct 22, 2015

Given a playbook like this:

- hosts: localhost
  tasks:
    - block:

        - include: failing_tasklist.yml

      always:

        - include: cleanup_tasklist.yml

Where failing_tasklist.yml looks like this:

- name: fail on purpose
  fail:
    msg: 'breaking things'

And cleanup_tasklist.yml looks like this:

- name: clean up
  debug:
    msg: 'cleaning things up'

I would expect Ansible to run cleanup_tasklist.yml, but the
resulting playbook run looks like this:

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [include] *****************************************************************
included: /home/lars/tmp/block-include-testcase/failing_tasklist.yml for localhost

TASK [fail on purpose] *********************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "breaking things"}

TASK [include] *****************************************************************

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=1   

So while it is parsing the include statement in the always section, it doesn't appear to be running it. The cleanup_tasklist.yml tasklist is run if there are no failures in the block: tasks, e.g.:

- hosts: localhost
  tasks:
    - block:

        - debug:
            msg: not breaking

      always:

        - include: cleanup_tasklist.yml
@larsks
Copy link
Contributor Author

larsks commented Oct 22, 2015

To save you some copy-and-pasting, here's the testcase as a git repository:

@larsks
Copy link
Contributor Author

larsks commented Oct 23, 2015

The problem is here, in lib/ansible/playbook/included_file.py:

def process_include_results(results, tqm, iterator, loader, variable_manager): included_files = []

    for res in results:
        if res._host.name in tqm._failed_hosts:
            continue

If we are handling an exception, then of course res._host.name is in
tqm._failed_hosts. At first glance, this seems like the wrong place
to be making this check (shouldn't this be happening per-task
already?), but I'm not familiar enough with the code to make that
determination.

@larsks larsks changed the title include fails in always: section of a block: include: fails during exception processing Oct 23, 2015
@jimi-c
Copy link
Member

jimi-c commented Oct 23, 2015

@larsks I agree, I think we can remove that without an ill-effect. I believe the host would not hit the include task if it had failed already, so checking that there is not required.

@jimi-c
Copy link
Member

jimi-c commented Oct 23, 2015

I do already have a complex include example in the samples/ directory, which you can test as follows:

# ansible-playbook -vv -i localhosts test_include.yml 

^ Running this with those lines removed shows the output I'd expect, so I'll go ahead and commit that fix.

@larsks
Copy link
Contributor Author

larsks commented Oct 23, 2015

Oh, sorry, I just sent in a PR for same. Feel free to ignore for yours...

larsks added a commit to larsks/ansible that referenced this issue Oct 23, 2015
prior to this commit, an attempt to use the `include:` directive would
fail in a `rescue:` or `always:` block if there were failures in the
main block task list.

Resolves ansible#12876.
@jimi-c
Copy link
Member

jimi-c commented Oct 23, 2015

Closing This Ticket

Hi!

We believe the above commit should resolve this problem for you. This will also be included in the next major release.

If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!

@jimi-c jimi-c added bug_report P2 Priority 2 - Issue Blocks Release labels Oct 23, 2015
@jimi-c jimi-c added this to the v2 milestone Oct 23, 2015
@jimi-c jimi-c self-assigned this Oct 23, 2015
photoninger pushed a commit to photoninger/ansible that referenced this issue Oct 26, 2015
prior to this commit, an attempt to use the `include:` directive would
fail in a `rescue:` or `always:` block if there were failures in the
main block task list.

Resolves ansible#12876.
@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. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants