I'm trying to dynamically include tasks along with using tags.  The issue 
I'm running into is that yes, its including the tasks file, but its not 
executing any of the tasks within that file.  After reading the Creating 
Reusable Playbooks guide, it appears this is by design for include_tasks.  
My question is why?  I'm now left having to add a tag to each individual 
task within the dynamically included tasks file.  This seems less than 
ideal.  Is there a better way I should be going about this?

Example:

playbook.yml
---
- name: Test
  hosts: localhost
  gather_facts: False
  connection: local
  tasks:
   - include_tasks: "{{ dynamic_variable }}.yml"
     tags: test


dynamic_variable.yml
---
- ping:



Playbook run *without *tag, tasks from dynamic_variable are executed
ansible-playbook playbook.yml
Vault password:

PLAY [Test] 
***********************************************************************************************************************************************************************************************************

TASK [include_tasks] 
**************************************************************************************************************************************************************************************************
included: /etc/ansible/dynamic_variable.yml for localhost

TASK [ping] 
***********************************************************************************************************************************************************************************************************
ok: [localhost]

PLAY RECAP 
************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0



Playbook run *with *tag, dynamic_variable file is included, none of the 
tasks contained within are executed due to not having tag.

 ansible-playbook playbook.yml -t test
Vault password:

PLAY [Test] 
***********************************************************************************************************************************************************************************************************

TASK [include_tasks] 
**************************************************************************************************************************************************************************************************
included: /etc/ansible/dynamic_variable.yml for localhost

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



The reason this is a problem for me is because within one of my dynamic 
tasks files I have 20-30 tasks.   I'd prefer not to have to add a tag to 
each individual task as that is how ansible used to function with the now 
deprecated include module.  It appears that if I roll back to before commit 
ebf971f 
<https://github.com/ansible/ansible/commit/ebf971f931290a113f738f658d7a6e095994e120>,
 
my issues go away.


So back to my original question.   Is there a better way I should be going 
about this?  If so, how?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/37977e70-13b9-4f26-8c7f-13f8bbb409fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to