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

Tags are not working for tasks under "include_tasks" #41540

Closed
oukooveu opened this issue Jun 14, 2018 · 8 comments
Closed

Tags are not working for tasks under "include_tasks" #41540

oukooveu opened this issue Jun 14, 2018 · 8 comments
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.

Comments

@oukooveu
Copy link

oukooveu commented Jun 14, 2018

SUMMARY

Tagged tasks under include_tasks are not executed.

Original issue: #32015 (closed, but not resolved).

ISSUE TYPE
  • Bug Report
COMPONENT NAME
include_tasks
import_tasks
tags
ANSIBLE VERSION
ansible 2.5.4
  config file = None
  configured module search path = [u'~/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = ~/virtualenv/ansible25/local/lib/python2.7/site-packages/ansible
  executable location = ~/virtualenv/ansible25/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
CONFIGURATION
$ ansible-config dump --only-changed
ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True
ANSIBLE_NOCOWS(env: ANSIBLE_NOCOWS) = True
DEFAULT_STDOUT_CALLBACK(env: ANSIBLE_STDOUT_CALLBACK) = debug
OS / ENVIRONMENT
$ cat /etc/issue
Linux Mint 18.3 Sylvia \n \l
STEPS TO REPRODUCE

play.yaml:

---
- hosts: localhost
  gather_facts: no
  tasks:

  - name: "Include tasks file"
    include_tasks: tasks.yaml

  - name: "Include_tasks tasks file"
    import_tasks: tasks.yaml

tasks.yaml:

- name: "Debug tag1"
  debug:
    msg: "init"
  tags:
  - tag1
EXPECTED RESULTS

While execution of ansible-playbook play.yaml -t tag1 debug message appears twice.

ACTUAL RESULTS

Tasks are executed only for import_tasks and not for include_tasks.

$ ansible-playbook play.yaml -t tag1
 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


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

TASK [Debug tag1] ******************************************************************************************************************************************************************
ok: [localhost] => {}

MSG:

init


PLAY RECAP *************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0   
@ansibot
Copy link
Contributor

ansibot commented Jun 14, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Jun 14, 2018

@kupchenko Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:

  • ansible version

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. and removed needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels Jun 14, 2018
@sivel
Copy link
Member

sivel commented Jun 14, 2018

This is the expected behavior. With include_tasks the tags applied to tasks within, do not impact whether or not the include_tasks task executes or not.

To solve for this scenario, you can either tag the include_tasks the same as the tasks within, or tag include_tasks with always:

  - name: "Include tasks file"
    include_tasks: tasks.yaml
    tags:
      - tag1
  - name: "Include tasks file"
    include_tasks: tasks.yaml
    tags:
      - always

If you have further questions please stop by IRC or the mailing list:

@sivel sivel closed this as completed Jun 14, 2018
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Jun 14, 2018
@apogrebnyak
Copy link

I agree that the behavior is documented, but the example, submitted by @kupchenko, shows clear violation of principal of least surprise.

Also, the old include directive worked in the manner that @kupchenko described, so, in retrospective, changing the include_* semantics was not a perfect decision (mainly because you cannot convert all of the old include statements to import_*)

Maybe adding a flag inherit_tags to include_* would be a solution here?

@bcoca
Copy link
Member

bcoca commented Jun 18, 2018

@apogrebnyak done #39236

The reason we migrated from include is that 'it worked sometimes' and there were no clear rules to show user having a 'static include' (now the import_) vs a dynamic include (the new include_X).

So the new actions are meant to give predictable and known working paths and with the latest addition should cover all the use cases include did.

@apogrebnyak
Copy link

@bcoca Thanks! Is it targeted for 2.7.0?

RenderQwerty added a commit to Otus-DevOps-2018-05/RenderQwerty_infra that referenced this issue Jul 24, 2018
RenderQwerty added a commit to Otus-DevOps-2018-05/RenderQwerty_infra that referenced this issue Jul 24, 2018
@kraduk
Copy link

kraduk commented Sep 7, 2018

This seems to work as a work around for propagating tags on a conditional include. for people who arrived here like me

- block:
  - import_tasks: tasks.yml
  when: some_test
  tags: tags_2_inherit

# pipenv run ansible-playbook  --version
Loading .env environment variables...
ansible-playbook 2.6.3
  config file = /home/xxx/767627_infrastructure_ansible2/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/.local/share/virtualenvs/767627_infrastructure_ansible2-paDAxRt4/local/lib/python2.7/site-packages/ansible
  executable location = /root/.local/share/virtualenvs/767627_infrastructure_ansible2-paDAxRt4/bin/ansible-playbook
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]


@ansible ansible locked and limited conversation to collaborators Feb 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

No branches or pull requests

7 participants
@sivel @apogrebnyak @bcoca @oukooveu @ansibot @kraduk and others