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

handle ignore_errors in loop #32546

Merged
merged 1 commit into from
Nov 8, 2017
Merged

Conversation

bcoca
Copy link
Member

@bcoca bcoca commented Nov 3, 2017

SUMMARY

most worked by accident, not using the correct task values
fixes #32384

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

core

ANSIBLE VERSION
2.4/2.5

@bcoca bcoca added this to Blocker in 2.4.x Blocker List Nov 3, 2017
@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bugfix_pull_request needs_triage Needs a first human triage before being processed. plugins/strategy support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 3, 2017
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 3, 2017
@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Nov 3, 2017
@guenhter
Copy link

guenhter commented Nov 3, 2017

- hosts: 127.0.0.1
  gather_facts: false
  vars:
    ignore_assertion_errors: false
  tasks:
    - name: With variable
      assert:
        that: item < 2
        msg: "{{item}} isn't < 2"
      ignore_errors: ignore_assertion_errors
      with_items:
        - 1
        - 2

Results in the error:

ERROR! The task includes an option with an undefined variable. The error was: 'item' is undefined

The error appears to have been in '/private/tmp/playbook.yml': line 6, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks:
    - name: With variable
      ^ here

On branch devel it runs through (falsely but it doesn't crashes)

@bcoca bcoca changed the title use templated task when processing results handle ignore_errors in loop Nov 3, 2017
ensures we get both a templated ignore_errors and a
correct 'summary' result for ignore_errors when used in loops

fixes ansible#32384
@bcoca
Copy link
Member Author

bcoca commented Nov 3, 2017

@guenhter sorry, try again now, i ended up finding a deeper error and ran through several iterations, but at this point it should be correct for all cases.

@guenhter
Copy link

guenhter commented Nov 3, 2017

@bcoca I checked and there is one thing left I don't completely understand (and maybe isn't even a bug).

In the playbook above:

When I use:

      ignore_errors: "{{ignore_assertion_errors}}"

This works perfectly fine. BUT

      ignore_errors: ignore_assertion_errors

seems always evaluate to false

I wasn't sure if this is expected so I checked with changed_when:

      changed_when: ignore_assertion_errors

This does exactly what I expect: when the variable is true, it show a change in the recap, if the variable is false it doesn't.

So the good news is, that your fix is working with the {{ variable }} expression, but just variable doesn't work.

@bcoca
Copy link
Member Author

bcoca commented Nov 3, 2017

when: clauses have an 'implied' {{ }} so they do not need it, every other keyword requires the {{}} to process variables.

@guenhter
Copy link

guenhter commented Nov 3, 2017

Ok, thanks for the clarification. Than this seems fine.

@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Nov 6, 2017
@bcoca bcoca merged commit d22627d into ansible:devel Nov 8, 2017
@bcoca bcoca deleted the use_templ_task_results branch November 8, 2017 00:54
@bcoca bcoca moved this from Blocker to Done in 2.4.2 in 2.4.x Blocker List Nov 8, 2017
@nelsg
Copy link

nelsg commented Feb 28, 2018

For information:
I'm faced the same issue when I upgraded from Ansible 2.2.1 to 2.3.2.
After some tests, this regression was introduced with Ansible 2.3.0.
Then caution if you planed to upgrade to a version higher than 2.2.3, choose at least version 2.4.2.

Maybe this fix must be integrated with future version 2.3.3, no ?

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. executor/task_executor plugins/strategy support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
No open projects
2.4.x Blocker List
Done in 2.4.2
Development

Successfully merging this pull request may close these issues.

ignore_errors always ignore failures when variable is used to control it
4 participants