<p dir="auto">While testing some playbooks with rpm_key module I have noticed that each time I run it it imports the same key. It would be good to have an native ansible option which would prevent importing already imported key.</p>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">ansible/lib/ansible/playbook/role/<strong>init</strong>.py<br>
ansible/lib/ansible/executor/play_iterator.py</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
"><pre class="notranslate"><code class="notranslate">ansible 2.1.0.0

</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">No change</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">In official ansible document site,<br>
<a href="http://docs.ansible.com/ansible/playbooks_roles.html" rel="nofollow">http://docs.ansible.com/ansible/playbooks_roles.html</a><br>
It said,<br>
Roles dependencies are always executed before the role that includes them, and are recursive. By default, roles can also only be added as a dependency once - if another role also lists it as a dependency it will not be run again.<br>
but sometimes, it doesn't work as expected, the same role were executed multiple times. Maybe we need consider what role object is? the same role definition with different variable input may be considered different role object, but if we add conditional dependency for a role, that is we use "when", is the role with "when" different with role without "when"?</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Suppose we have a playbook, which has a role named csf that depends on csfA/csfB/csfC, and csfB and csfA depends on csfC in some condition,</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# main playbook
#ls.yml

---
- name: play1
  hosts: SSHproxy
  remote_user: root
  gather_facts: false
  roles:
    - {role: csf, taskN: task1 }

#csf role definition
#roles/csf/meta/main.yml

---
dependencies:
- role: csfC
- role: csfA
- role: csfB

# csfA role defintion
#roles/csfA/meta/main.yml

---
dependencies:
- {role: csfC, when: taskN=='task1'}

#roles/csfA/tasks/main.yml
- shell: ls


# csfB role definition
#roles/csfB/meta/main.yml

---
dependencies:
- {role: csfC, when: taskN=='task1'}

#roles/csfB/tasks/main.yml
- shell: ls
"><pre class="notranslate"><code class="notranslate"># main playbook
#ls.yml

---
- name: play1
  hosts: SSHproxy
  remote_user: root
  gather_facts: false
  roles:
    - {role: csf, taskN: task1 }

#csf role definition
#roles/csf/meta/main.yml

---
dependencies:
- role: csfC
- role: csfA
- role: csfB

# csfA role defintion
#roles/csfA/meta/main.yml

---
dependencies:
- {role: csfC, when: taskN=='task1'}

#roles/csfA/tasks/main.yml
- shell: ls


# csfB role definition
#roles/csfB/meta/main.yml

---
dependencies:
- {role: csfC, when: taskN=='task1'}

#roles/csfB/tasks/main.yml
- shell: ls

</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;!--- What did you expect to happen when running the steps above? --&gt;
role csfC will be executed just one time

PLAY [play1] *******************************************************************

TASK [csfC : command] **********************************************************
changed: [SSHproxy]

TASK [csfA : command] **********************************************************
changed: [SSHproxy]

TASK [csfB : command] **********************************************************
changed: [SSHproxy]

PLAY RECAP *********************************************************************
SSHproxy : ok=3 changed=3 unreachable=0 failed=0"><pre class="notranslate"><code class="notranslate">&lt;!--- What did you expect to happen when running the steps above? --&gt;
role csfC will be executed just one time

PLAY [play1] *******************************************************************

TASK [csfC : command] **********************************************************
changed: [SSHproxy]

TASK [csfA : command] **********************************************************
changed: [SSHproxy]

TASK [csfB : command] **********************************************************
changed: [SSHproxy]

PLAY RECAP *********************************************************************
SSHproxy : ok=3 changed=3 unreachable=0 failed=0
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="role csfC were executed two times.

PLAY [play1] *******************************************************************

TASK [csfC : command] **********************************************************
changed: [SSHproxy]

TASK [csfC : command] **********************************************************
changed: [SSHproxy]

TASK [csfA : command] **********************************************************
changed: [SSHproxy]

TASK [csfB : command] **********************************************************
changed: [SSHproxy]

PLAY RECAP *********************************************************************
SSHproxy : ok=4 changed=4 unreachable=0 failed=0"><pre class="notranslate"><code class="notranslate">role csfC were executed two times.

PLAY [play1] *******************************************************************

TASK [csfC : command] **********************************************************
changed: [SSHproxy]

TASK [csfC : command] **********************************************************
changed: [SSHproxy]

TASK [csfA : command] **********************************************************
changed: [SSHproxy]

TASK [csfB : command] **********************************************************
changed: [SSHproxy]

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