Hi,

Thanks for pointing that out. I understood the concept now (specifying a tag to 
a role means flagging all role's tasks with the tag).
The reason why I wanted to do it differently is because of the following 
scenario:

Assume you have tasks in two different roles. First, you want to execute a 
subset of tasks in the roles (e.g. Checks before an update), then you want to 
execute another subset (e.g. The actual update).

If roles belong to different entities of the infrastructure, and all tasks of 
one role are located in its main.yml task file, I wanted to execute tasks this 
way: first all tasks tagged with checkupdate, then all tasks with update. The 
first update task should only be executed if all checkupdate tasks suceeded.

While I can concatenate playbooks (one for checkupdate, one for update), I 
haven't found a way to execute the tasks from a single playbook.

However (if you dont correct me on this), I came to the conclusion, that my 
role setup was wrong from the start. Or putting it in another way, I wanted an 
execution order of tasks in the way RoleA: T1a, RoleA: T2a, RoleB: T1b, RoleA: 
T3a, ...
I guess I should refactor my roles so that the checkupdate tasks are be tagged 
as update instead and executed first, and it should not matter if role A is 
completely executed before role B...?

Anyway, thanks again for your clarification.



> Am 12.06.2014 um 00:39 schrieb Michael DeHaan <mich...@ansible.com>:
> 
> 
> When you use tags you are selecting what to execute.  There are no "negative 
> tags".
> 
> Both tags above have been applied with "update", and you've requested all 
> things with update to run.
> 
> 
>> On Wed, Jun 11, 2014 at 10:35 AM, Michael Hauck <michael.ha...@avenyou.com> 
>> wrote:
>> I think I found the problem in my code:
>> 
>> If I include the role tmp in my playbook using
>> 
>> 
>>   - { role: tmp, tags: update }
>> 
>> it seems like all tasks of the role are executed, and the tags are not 
>> respected.
>> 
>> If I put the role in the playbook without denoting a tag, the tags are 
>> respected if specified in the ansible-playbook command, e.g. using --tags 
>> "update"
>> 
>> Is this intended behaviour or a bug?
>> 
>> 
>>> On Tuesday, June 10, 2014 8:59:12 PM UTC+2, Michael Hauck wrote:
>>> I have a problem that I want to execute only tasks with certain tags from a 
>>> playbook, but this does not work.
>>> 
>>> My playbook looks as follows:
>>> 
>>> #playbook.yml
>>> - hosts: appservers
>>>   remote_user: myuser
>>>   roles:
>>>     - { role: tmp, tags: update }
>>> 
>>> The tmp role task file looks as follows:
>>> 
>>> # roles/tmp/tasks/main.yml
>>> - name: Test 1
>>>   debug: msg="Test 1"
>>>   tags: anothertag
>>> 
>>> - name: Test 2
>>>   debug: msg="Test 2"
>>>   tags: update
>>> 
>>> 
>>> If I execute the playbook with
>>> 
>>> ansible-playbook -i inventory/test playbook.yml
>>> 
>>> or
>>> 
>>> ansible-playbook -i inventory/test playbook.yml --tags=update
>>> 
>>> all two tasks are executed both times.
>>> I do not want task "Test 1" to be executed.
>>> 
>>> I can achieve this by running ansible-playbook with the option 
>>> --skip-tags=anothertag, but this not what I want.
>>> Do you know how I can get that to work or where my scripts are erroneous?
>>> 
>>> Thanks,
>>> Michael
>> 
>> -- 
>> 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/486c6fcf-9f5e-4bcc-88b8-9a2b8afe4d3d%40googlegroups.com.
>> 
>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Ansible Project" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/ansible-project/sHqiwdCxOkI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CA%2BnsWgwQq8JBAf4AV7DVcQUDgN53BA_vtd-zZG9m-vCegfwdOA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/5E9AFA0B-3ACF-4C1D-9625-480AFE902AEF%40avenyou.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to