<p dir="auto">Create two roles, for instance "nginx" and "tomcat"; define variable files in each role with a 'version' variable, set to match expected versions of nginx and tomcat; create a playbook which associates both 'nginx' and 'tomcat' roles to a set of hosts.</p>
<p dir="auto">Depending on order of execution, it appears that ansible overwrites the tomcat:version property with the nginx:version property, and then attempts to install tomcat-{{nginx:version}} which fails.</p>
<p dir="auto">Either documentation should be updated to reflect the idea that roles maintain variables in a global namespace, or roles should be updated to auto-namespace vars files inside them, such that similarly named vars can co-exist between roles.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">Playbooks/Roles</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.2.1.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"><code class="notranslate">nowcows=1</code></p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A (Ubuntu)</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When a role is invoked through a playbook and also referenced as a dependency it is executed twice.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="==&gt; playbook.yml &lt;==
---
- hosts: localhost

  roles:
    - role: A
    - role: B
    - role: C

==&gt; roles/A/tasks/main.yml &lt;==
---
- debug: msg=A

==&gt; roles/B/meta/main.yml &lt;==
dependencies:
  - name: A

==&gt; roles/B/tasks/main.yml &lt;==
---
- debug: msg=B

==&gt; roles/C/meta/main.yml &lt;==
dependencies:
  - name: A

==&gt; roles/C/tasks/main.yml &lt;==
---
- debug: msg=C"><pre class="notranslate"><span class="pl-s">==&gt; playbook.yml &lt;==</span>
---
- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>

  <span class="pl-ent">roles</span>:
    - <span class="pl-ent">role</span>: <span class="pl-s">A</span>
    - <span class="pl-ent">role</span>: <span class="pl-s">B</span>
    - <span class="pl-ent">role</span>: <span class="pl-s">C</span>

<span class="pl-s">==&gt; roles/A/tasks/main.yml &lt;==</span>
---
- <span class="pl-ent">debug</span>: <span class="pl-s">msg=A</span>

<span class="pl-s">==&gt; roles/B/meta/main.yml &lt;==</span>
<span class="pl-ent">dependencies</span>:
  - <span class="pl-ent">name</span>: <span class="pl-s">A</span>

<span class="pl-s">==&gt; roles/B/tasks/main.yml &lt;==</span>
---
- <span class="pl-ent">debug</span>: <span class="pl-s">msg=B</span>

<span class="pl-s">==&gt; roles/C/meta/main.yml &lt;==</span>
<span class="pl-ent">dependencies</span>:
  - <span class="pl-ent">name</span>: <span class="pl-s">A</span>

<span class="pl-s">==&gt; roles/C/tasks/main.yml &lt;==</span>
---
- <span class="pl-ent">debug</span>: <span class="pl-s">msg=C</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Have roles A, B, C each execute once.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Role A runs twice, then role B and C run.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using /etc/ansible/ansible.cfg as config file
 [WARNING]: provided hosts list is empty, only localhost is available

Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: playbook.yml *********************************************************
1 plays in playbook.yml

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/setup.py
&lt;127.0.0.1&gt; ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
&lt;127.0.0.1&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p &quot;` echo ~/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035 `&quot; &amp;&amp; echo ansible-tmp-1488405550.52-260200123218035=&quot;` echo ~/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035 `&quot; ) &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; PUT /tmp/tmpF6ZqnV TO /home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/setup.py
&lt;127.0.0.1&gt; EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/ /home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/setup.py &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; EXEC /bin/sh -c '/usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/setup.py; rm -rf &quot;/home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/&quot; &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'
ok: [localhost]

TASK [A : debug] ***************************************************************
task path: /home/ubuntu/demo-ansible-multiple_role-bug/roles/A/tasks/main.yml:2
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;A&quot;
}

TASK [A : debug] ***************************************************************
task path: /home/ubuntu/demo-ansible-multiple_role-bug/roles/A/tasks/main.yml:2
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;A&quot;
}

TASK [B : debug] ***************************************************************
task path: /home/ubuntu/demo-ansible-multiple_role-bug/roles/B/tasks/main.yml:2
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;B&quot;
}

TASK [C : debug] ***************************************************************
task path: /home/ubuntu/demo-ansible-multiple_role-bug/roles/C/tasks/main.yml:2
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;C&quot;
}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">Using /etc/ansible/ansible.cfg as config file
 [WARNING]: provided hosts list is empty, only localhost is available

Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: playbook.yml *********************************************************
1 plays in playbook.yml

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/system/setup.py
&lt;127.0.0.1&gt; ESTABLISH LOCAL CONNECTION FOR USER: ubuntu
&lt;127.0.0.1&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035 `" &amp;&amp; echo ansible-tmp-1488405550.52-260200123218035="` echo ~/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035 `" ) &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; PUT /tmp/tmpF6ZqnV TO /home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/setup.py
&lt;127.0.0.1&gt; EXEC /bin/sh -c 'chmod u+x /home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/ /home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/setup.py &amp;&amp; sleep 0'
&lt;127.0.0.1&gt; EXEC /bin/sh -c '/usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/setup.py; rm -rf "/home/ubuntu/.ansible/tmp/ansible-tmp-1488405550.52-260200123218035/" &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'
ok: [localhost]

TASK [A : debug] ***************************************************************
task path: /home/ubuntu/demo-ansible-multiple_role-bug/roles/A/tasks/main.yml:2
ok: [localhost] =&gt; {
    "msg": "A"
}

TASK [A : debug] ***************************************************************
task path: /home/ubuntu/demo-ansible-multiple_role-bug/roles/A/tasks/main.yml:2
ok: [localhost] =&gt; {
    "msg": "A"
}

TASK [B : debug] ***************************************************************
task path: /home/ubuntu/demo-ansible-multiple_role-bug/roles/B/tasks/main.yml:2
ok: [localhost] =&gt; {
    "msg": "B"
}

TASK [C : debug] ***************************************************************
task path: /home/ubuntu/demo-ansible-multiple_role-bug/roles/C/tasks/main.yml:2
ok: [localhost] =&gt; {
    "msg": "C"
}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=0   
</code></pre></div>