<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">devel (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/e0147f18b1a5355d391dd9482d6afaf89ace8264/hovercard" href="https://github.com/ansible/ansible/commit/e0147f18b1a5355d391dd9482d6afaf89ace8264"><tt>e0147f1</tt></a>)</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">When trying to restrict tasks by tags all tasks are being executed. Regardless of the specified tags.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Hostfile test:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="localhost   ansible_ssh_user=root"><pre class="notranslate"><code class="notranslate">localhost   ansible_ssh_user=root
</code></pre></div>
<p dir="auto">Playbook test-tags.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: localhost
  roles:
    - test-tags"><pre class="notranslate"><code class="notranslate">- hosts: localhost
  roles:
    - test-tags
</code></pre></div>
<p dir="auto">/roles/test-tags/tasks/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- include: foo.yml
  tags: foo

- include: bar.yml
  tags: bar"><pre class="notranslate"><code class="notranslate">- include: foo.yml
  tags: foo

- include: bar.yml
  tags: bar
</code></pre></div>
<p dir="auto">/roles/test-tags/tasks/foo.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- debug: msg=&quot;foo&quot;"><pre class="notranslate"><code class="notranslate">- debug: msg="foo"
</code></pre></div>
<p dir="auto">/roles/test-tags/tasks/bar.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- debug: msg=&quot;bar&quot;"><pre class="notranslate"><code class="notranslate">- debug: msg="bar"
</code></pre></div>
<p dir="auto">Execute playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -i test test-tags.yml --tags bar --list-tasks"><pre class="notranslate"><code class="notranslate">ansible-playbook -i test test-tags.yml --tags bar --list-tasks
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="playbook: test-tags.yml

  play #1 (localhost):
    debug msg=&quot;bar&quot; (tags: all, bar)"><pre class="notranslate"><code class="notranslate">playbook: test-tags.yml

  play #1 (localhost):
    debug msg="bar" (tags: all, bar)
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="playbook: test-tags.yml

  play #1 (localhost):
    debug msg=&quot;foo&quot; (tags: all, foo, bar)
    debug msg=&quot;bar&quot; (tags: all, foo, bar)"><pre class="notranslate"><code class="notranslate">playbook: test-tags.yml

  play #1 (localhost):
    debug msg="foo" (tags: all, foo, bar)
    debug msg="bar" (tags: all, foo, bar)
</code></pre></div>
<p dir="auto">Please note that I added a debug output to ansible-playbook (see PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="29260114" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/6434" data-hovercard-type="pull_request" data-hovercard-url="/ansible/ansible/pull/6434/hovercard" href="https://github.com/ansible/ansible/pull/6434">#6434</a>) to see which tags are compiled for each task.<br>
The problem seems to be: All tags are assigned to every task. So restricting via tag is completely useless in the current develop-branch.</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug report in tag handling</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">Latest devel, as per git bisect, bug was introduced in <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/6577ff5f85bf27048739013d91066c7b4e1dd466/hovercard" href="https://github.com/ansible/ansible/commit/6577ff5f85bf27048739013d91066c7b4e1dd466"><tt>6577ff5</tt></a></p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Ubuntu, but N/A</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">When running a larger playbooks contanin multiple plays with different tags, and running it with specifying a particular tag, all tasks in those plays that contain (tasks with) that tag are ran, instead of only those tasks that have the specific tag.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  1 - name: Restart Tomcat Servers                                                  
  2   hosts: tomcat                                                                 
  3   gather_facts: False                                                           
  4   tasks:                                                                        
  5   - name: trigger stop                                                          
  6     debug: var=tomcat_version                                                   
  7     changed_when: True                                                          
  8     notify:                                                                     
  9     - stop_tomcat                                                               
 10     tags: stop                                                                  
 11   - name: trigger start                                                         
 12     debug: var=tomcat_version                                                   
 13     changed_when: True                                                          
 14     notify:                                                                     
 15     - start_tomcat                                                              
 16     tags: start                                                                 
 17   handlers:                                                                     
 18   - include: handlers/tomcat.yml   "><pre class="notranslate"><code class="notranslate">  1 - name: Restart Tomcat Servers                                                  
  2   hosts: tomcat                                                                 
  3   gather_facts: False                                                           
  4   tasks:                                                                        
  5   - name: trigger stop                                                          
  6     debug: var=tomcat_version                                                   
  7     changed_when: True                                                          
  8     notify:                                                                     
  9     - stop_tomcat                                                               
 10     tags: stop                                                                  
 11   - name: trigger start                                                         
 12     debug: var=tomcat_version                                                   
 13     changed_when: True                                                          
 14     notify:                                                                     
 15     - start_tomcat                                                              
 16     tags: start                                                                 
 17   handlers:                                                                     
 18   - include: handlers/tomcat.yml   
</code></pre></div>
<p dir="auto">running <code class="notranslate">ansible-playbook util-tomcat-restart.yml -t stop</code> will run both trigger tasks, not just the stop task.</p>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">Run only the tasks that have a particular tag.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">All tasks from the play that contain some tasks with a given tag are ran.</p>