The explanation listed at
https://github.com/ansible/ansible/issues/35065#issuecomment-358998670
should hopefully answer your questions.

If you want an attribute to be inherited on the tasks, you should use
`import_tasks` as opposed to `include_tasks`.  Attributes on
`include_tasks` should apply to the include only, whereas attributes on
`import_tasks` will be inherited by the imported tasks.

On Fri, Jan 19, 2018 at 10:03 AM, Mike Klebolt <mikest...@gmail.com> wrote:

> I've also tried wrapping all the tasks in the dynamically included file in
> a block and adding a tag to the block.  This achieves what I'm trying to
> accomplish but doesn't feel like the proper approach.
>
>
> On Friday, January 19, 2018 at 9:58:05 AM UTC-6, Mike Klebolt wrote:
>>
>> 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/6368451d-ed81-47f6-b2d9-8946cfca3844%40googlegroups.
> com
> <https://groups.google.com/d/msgid/ansible-project/6368451d-ed81-47f6-b2d9-8946cfca3844%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Matt Martz
@sivel
sivel.net

-- 
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/CAD8N0v-1LwYEcXctcHaRhWq3YdVsCk8QWSeTgOpG0ozxq-fqmg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to