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

bug: included nested block with conditions results in unexpeced tasks execution #15926

Closed
resmo opened this issue May 19, 2016 · 1 comment
Closed
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Milestone

Comments

@resmo
Copy link
Contributor

resmo commented May 19, 2016

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
2.2
2.1 rc3
SUMMARY

if include is used to include a tasks list with a nested block, a condition is not evaluated correctly.

STEPS TO REPRODUCE

given a simple role which has an include in main.yml for inc.yml and in inc.yml there is a nested block.
However since the when condition of the outer block is false, no task should be exectued, but the nested block 2.1 is executed.

# file: common/vars/main.yml 

---
condition: ok
# file: common/tasks/main.yml 

---
- include: inc.yml
# file: common/tasks/inc.yml 

---
- block:
  - name: block 2
    fail: msg="this should not run"
  - block:
    - name: block 2.1
      fail: msg="this should not run" 
  when: condition == 'nok'

The bug does not show up without include.

EXPECTED RESULTS
 $ ansible-playbook common.yml  -i hosts

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

TASK [common : include] ********************************************************
included: /home/resmo/tmp/test-block/common/tasks/inc.yml for localhost

TASK [common : block 2] *************************************************
skipping: [localhost]

TASK [common : block 2.1] ******************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0 
ACTUAL RESULTS
 $ ansible-playbook common.yml  -i hosts

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

TASK [common : include] ********************************************************
included: /home/resmo/tmp/test-block/common/tasks/inc.yml for localhost

TASK [common : block 2] *************************************************
skipping: [localhost]

TASK [common : block 2.1] ******************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "this should not run"}
    to retry, use: --limit @common.retry

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1
@resmo resmo changed the title include a nested block having conditions results in unexpeced tasks execution bug: include: block: when: nested block with conditions results in unexpeced tasks execution May 19, 2016
@resmo resmo changed the title bug: include: block: when: nested block with conditions results in unexpeced tasks execution bug: nested block with conditions results in unexpeced tasks execution May 19, 2016
@resmo resmo changed the title bug: nested block with conditions results in unexpeced tasks execution bug: included nested block with conditions results in unexpeced tasks execution May 19, 2016
@jctanner jctanner added bug_report P2 Priority 2 - Issue Blocks Release labels May 19, 2016
@jctanner jctanner added this to the 2.2.0 milestone May 19, 2016
jimi-c added a commit that referenced this issue May 23, 2016
We previously changed block behavior to prefer includes over parent
blocks, which broke inheritence in nested blocks.

Fixes #15926
@jimi-c jimi-c closed this as completed in 72b29d1 May 23, 2016
@jimi-c
Copy link
Member

jimi-c commented May 23, 2016

Closing This Ticket

Hi!

We believe the above commit should resolve this problem for you. This will also be included in the next 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!

abadger pushed a commit that referenced this issue May 25, 2016
We previously changed block behavior to prefer includes over parent
blocks, which broke inheritence in nested blocks.

Fixes #15926
@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

No branches or pull requests

4 participants