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

Dynamically excluded tasks are still evaluated #31593

Closed
foben opened this issue Oct 11, 2017 · 6 comments · Fixed by #31604
Closed

Dynamically excluded tasks are still evaluated #31593

foben opened this issue Oct 11, 2017 · 6 comments · Fixed by #31604
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@foben
Copy link

foben commented Oct 11, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

include_tasks

ANSIBLE VERSION
ansible-playbook 2.5.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/felix/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible-2.5.0-py2.7.egg/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.13 (default, May 10 2017, 20:04:28) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
CONFIGURATION
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30
OS / ENVIRONMENT

Fedora 24, running local playbook

SUMMARY

The include_tasks feature does not behave as expected. Particularly the 'dynamic' aspect that is emphasized in the documentation does not work.
Executing the playbook.yml posted below:

ansible-playbook playbook.yml

It seems to me that the pre 2.4 behavior is still present - the condition is simply applied to every single included task, instead of dynamically skipping the include due to the failing conditional.
The documentation here suggests a different behavior.

STEPS TO REPRODUCE

playbook.yml:

---
- hosts: 127.0.0.1
  gather_facts: no

  tasks:
  
  - name: "Include Task"
    include_tasks: include.yml
    when: False

include.yml:

- name: "Include 1"
  debug:
    msg: "Include 1"

- name: "Include 2"
  debug:
    msg: "Include 2"

- name: "Include 3"
  debug:
    msg: "Include 3"
EXPECTED RESULTS

Expected something along those lines:


PLAY [127.0.0.1] *********************************************************************************************************************************************

TASK [Include Task] *********************************************************************************************************************************************
skipping: [127.0.0.1]

PLAY RECAP ***************************************************************************************************************************************************
127.0.0.1                  : ok=0    changed=0    unreachable=0    failed=0   

ACTUAL RESULTS

PLAY [127.0.0.1] *********************************************************************************************************************************************

TASK [Include 1] *********************************************************************************************************************************************
skipping: [127.0.0.1]

TASK [Include 2] *********************************************************************************************************************************************
skipping: [127.0.0.1]

TASK [Include 3] *********************************************************************************************************************************************
skipping: [127.0.0.1]

PLAY RECAP ***************************************************************************************************************************************************
127.0.0.1                  : ok=0    changed=0    unreachable=0    failed=0   

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bug_report module This issue/PR relates to a module. 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 Oct 11, 2017
@sivel
Copy link
Member

sivel commented Oct 11, 2017

You seem to be mixing terms here. You reference include_tasks which is the dynamic version, however your playbook is using import_tasks which is the static version.

@foben
Copy link
Author

foben commented Oct 11, 2017

I'm sorry, I copied the playbook in the wrong version. I tried import_tasks to compare the two.
I am actually referring to the dynamic version, include_tasks. I have updated the example playbook accordingly.
As a side note: both import_tasks and include_tasks produce the exact output in this example,
which also highlights the issue.

@sivel
Copy link
Member

sivel commented Oct 11, 2017

Ok, it seems this was broken in e609618

Since e609618 include_tasks and import_tasks both seem to work as import_tasks was designed to.

cc @jimi-c

@sivel
Copy link
Member

sivel commented Oct 11, 2017

An updated playbook that uses both:

---
- hosts: localhost
  gather_facts: no
  tasks:
  - name: "Include Task"
    include_tasks: include.yml
    when: False

  - name: "Import Task"
    import_tasks: include.yml
    when: False

@sivel
Copy link
Member

sivel commented Oct 11, 2017

I've also put together a gist to show this behavior:

https://gist.github.com/sivel/a49acdc41faa609274ed11141b6e99eb

@foben
Copy link
Author

foben commented Oct 11, 2017

One further note: The commit has also been cherry-picked to the stable-2.4 branch, which is where I noticed it initially:

ef96329

@abadger abadger added this to TODO: Blocker in 2.4.x Blocker List Oct 11, 2017
jimi-c added a commit to jimi-c/ansible that referenced this issue Oct 11, 2017
An incorrect removal of a conditional resulted in include_tasks falling
through to the old static detection mechanism incorrectly. This restores
the previous conditional check.

Fixes ansible#31593
@abadger abadger removed this from TODO: Blocker in 2.4.x Blocker List Oct 11, 2017
abadger pushed a commit that referenced this issue Oct 12, 2017
An incorrect removal of a conditional resulted in include_tasks falling
through to the old static detection mechanism incorrectly. This restores
the previous conditional check.

Fixes #31593

(cherry picked from commit 3ef4f7e)
abadger pushed a commit that referenced this issue Oct 12, 2017
An incorrect removal of a conditional resulted in include_tasks falling
through to the old static detection mechanism incorrectly. This restores
the previous conditional check.

Fixes #31593
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Oct 13, 2017
BondAnthony pushed a commit to BondAnthony/ansible that referenced this issue Oct 14, 2017
An incorrect removal of a conditional resulted in include_tasks falling
through to the old static detection mechanism incorrectly. This restores
the previous conditional check.

Fixes ansible#31593
mtb-xt pushed a commit to mtb-xt/ansible that referenced this issue Oct 15, 2017
An incorrect removal of a conditional resulted in include_tasks falling
through to the old static detection mechanism incorrectly. This restores
the previous conditional check.

Fixes ansible#31593
@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 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. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants