<p dir="auto">Using ansible 1.9.4. reconfirmed by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/global/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/global">@global</a> on 2.2.0.0</p>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2.2.0.0"><pre class="notranslate"><code class="notranslate">2.2.0.0
</code></pre></div>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">tags</p>
<p dir="auto">If I have a role - <code class="notranslate">example-3</code> which depends on <code class="notranslate">example-1</code> then provisioning using <code class="notranslate">--tags=example-3</code> will only run <code class="notranslate">example-1</code> if  <code class="notranslate">example-3</code> is the first role in the list of roles.</p>
<p dir="auto">Below are is the output for each case:</p>
<h3 dir="auto">Dependencies do not run for <code class="notranslate">--tags=example-3</code></h3>
<p dir="auto">Playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: Demo with role tagging
  hosts: vagrant
  sudo: yes
  roles:
    - { role: 'example-2', tags: 'example-2' }
    - { role: 'example-3', tags: 'example-3' }"><pre class="notranslate"><code class="notranslate">
---
- name: Demo with role tagging
  hosts: vagrant
  sudo: yes
  roles:
    - { role: 'example-2', tags: 'example-2' }
    - { role: 'example-3', tags: 'example-3' }
</code></pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [Demo with role tagging] *************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.12.148]

TASK: [example-3 | Running example 3] *****************************************
ok: [192.168.12.148] =&gt; {
    &quot;msg&quot;: &quot;Example 3&quot;
 }

PLAY RECAP ********************************************************************
192.168.12.148             : ok=2    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [Demo with role tagging] *************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.12.148]

TASK: [example-3 | Running example 3] *****************************************
ok: [192.168.12.148] =&gt; {
    "msg": "Example 3"
 }

PLAY RECAP ********************************************************************
192.168.12.148             : ok=2    changed=0    unreachable=0    failed=0
</code></pre></div>
<h3 dir="auto">Dependencies do run for <code class="notranslate">--tags=example-3</code></h3>
<p dir="auto">Playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: Demo with role tagging
  hosts: vagrant
  sudo: yes
  roles:
    - { role: 'example-3', tags: 'example-3' }"><pre class="notranslate"><code class="notranslate">
---
- name: Demo with role tagging
  hosts: vagrant
  sudo: yes
  roles:
    - { role: 'example-3', tags: 'example-3' }
</code></pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [Demo with role tagging] *************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.12.148]

TASK: [example-1 | Running example 1] *****************************************
ok: [192.168.12.148] =&gt; {
    &quot;msg&quot;: &quot;Example 1&quot;
}

TASK: [example-3 | Running example 3] *****************************************
ok: [192.168.12.148] =&gt; {
    &quot;msg&quot;: &quot;Example 3&quot;
}

PLAY RECAP ********************************************************************
192.168.12.148             : ok=3    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [Demo with role tagging] *************************************************

GATHERING FACTS ***************************************************************
ok: [192.168.12.148]

TASK: [example-1 | Running example 1] *****************************************
ok: [192.168.12.148] =&gt; {
    "msg": "Example 1"
}

TASK: [example-3 | Running example 3] *****************************************
ok: [192.168.12.148] =&gt; {
    "msg": "Example 3"
}

PLAY RECAP ********************************************************************
192.168.12.148             : ok=3    changed=0    unreachable=0    failed=0
</code></pre></div>
<p dir="auto">There is a sample repo <a href="https://github.com/pajtai/ansible-tags-example">here</a> which runs the <code class="notranslate">example-3</code> tag on vagrant provisioning. If you run <code class="notranslate">vagrant up</code> or subsequently <code class="notranslate">vagrant provision</code> or <code class="notranslate">ansible-playbook</code> against the VM box, then you can see the case where the dependencies do not run. To get the dependencies to run comment out <a href="https://github.com/pajtai/ansible-tags-example/blob/master/ansible/site.yml#L6">the first role</a>.</p>
<p dir="auto">This problem is referenced by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ghostwords/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ghostwords">@ghostwords</a> <a href="https://github.com/ansible/ansible/issues/4339#issuecomment-160677433" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/4339/hovercard">here</a></p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">roles + tags</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Irrelevant</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">It will be very convenient have possibility run only part of role.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Come from <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="134308687" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/14525" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/14525/hovercard" href="https://github.com/ansible/ansible/issues/14525">#14525</a>.</p>
<p dir="auto">Playbook:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- hosts: localhost
  connection: local
  roles:
    - testdep"><pre class="notranslate"><code class="notranslate">- hosts: localhost
  connection: local
  roles:
    - testdep
</code></pre></div>
<p dir="auto">role <code class="notranslate">test</code>/tasks/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Task with tag1
  raw: echo Run task with tag1
  tags: tag1

- name: Task with tag2
  raw: echo Run task with tag2
  tags: tag2"><pre class="notranslate"><code class="notranslate">- name: Task with tag1
  raw: echo Run task with tag1
  tags: tag1

- name: Task with tag2
  raw: echo Run task with tag2
  tags: tag2
</code></pre></div>
<p dir="auto">It will be very helpful use it in dependency a <em>part of other role</em> in similar to <code class="notranslate">ansible-playbook</code> run way:</p>
<p dir="auto">role <code class="notranslate">testdep</code>/meta/main.yml:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="dependencies:
  - { role: test, only-tags: tag1 }
  - { role: test, skip-tags: [ 'tag1' ] }"><pre class="notranslate"><code class="notranslate">dependencies:
  - { role: test, only-tags: tag1 }
  - { role: test, skip-tags: [ 'tag1' ] }
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<ul dir="auto">
<li>For case of</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  - { role: test, only-tags: tag1 }"><pre class="notranslate"><code class="notranslate">  - { role: test, only-tags: tag1 }
</code></pre></div>
<p dir="auto">expected what only tasks with <code class="notranslate">tag1</code> from role <code class="notranslate">test</code> will be applied.</p>
<ul dir="auto">
<li>Vise versa for case of</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  - { role: test, skip-tags: [ 'tag1' ] }"><pre class="notranslate"><code class="notranslate">  - { role: test, skip-tags: [ 'tag1' ] }
</code></pre></div>
<p dir="auto">all tasks without tag <code class="notranslate">tag1</code> will be run.</p>