<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">module  lineinfile</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2.3.0.0"><pre class="notranslate"><code class="notranslate">2.3.0.0
</code></pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- hosts: 127.0.0.1
  tasks:
    - name:
      lineinfile:
        dest: foo.txt
        regexp: &quot;msgid aaaa\nmsgstr bbbbb\n&quot;
        line:   &quot;msgid aaaa\nmsgstr bbbbb\n&quot;"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">127.0.0.1</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">name</span>:
      <span class="pl-ent">lineinfile</span>:
        <span class="pl-ent">dest</span>: <span class="pl-s">foo.txt</span>
        <span class="pl-ent">regexp</span>: <span class="pl-s"><span class="pl-pds">"</span>msgid aaaa<span class="pl-cce">\n</span>msgstr bbbbb<span class="pl-cce">\n</span><span class="pl-pds">"</span></span>
        <span class="pl-ent">line</span>:   <span class="pl-s"><span class="pl-pds">"</span>msgid aaaa<span class="pl-cce">\n</span>msgstr bbbbb<span class="pl-cce">\n</span><span class="pl-pds">"</span></span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# echo &gt; foo.txt
# ansible-playbook aa.yaml
# ansible-playbook aa.yaml
# ansible-playbook aa.yaml
# cat foo.txt 
msgid aaaa
msgstr bbbbb

msgid aaaa
msgstr bbbbb

msgid aaaa
msgstr bbbbb"><pre class="notranslate"><code class="notranslate"># echo &gt; foo.txt
# ansible-playbook aa.yaml
# ansible-playbook aa.yaml
# ansible-playbook aa.yaml
# cat foo.txt 
msgid aaaa
msgstr bbbbb

msgid aaaa
msgstr bbbbb

msgid aaaa
msgstr bbbbb
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">Role dependencies</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.0.0
  config file = /home/kyle/.ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.2.0.0
  config file = /home/kyle/.ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[defaults]
inventory = ~/.ansible/hosts
ansible_managed = Managed by ansible. All changes will be overwritten
ssh_args = -o ControlMaster=auto -o ControlPersist=60s StrictHostKeyChecking=no
ask_vault_pass = yes
retry_files_enabled = False"><pre class="notranslate"><code class="notranslate">[defaults]
inventory = ~/.ansible/hosts
ansible_managed = Managed by ansible. All changes will be overwritten
ssh_args = -o ControlMaster=auto -o ControlPersist=60s StrictHostKeyChecking=no
ask_vault_pass = yes
retry_files_enabled = False
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Debian Stretch and Debian Sid managing Debian Stretch</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">I have roles: <code class="notranslate">example_1</code>, <code class="notranslate">example_2</code>, <code class="notranslate">dependency_1</code> and <code class="notranslate">dependency_2</code>. <code class="notranslate">dependency_1</code> is set to be duplicated (<code class="notranslate">allow_duplicates: yes</code>) and <code class="notranslate">dependency_2</code> also depends on <code class="notranslate">dependency_1</code>.</p>
<p dir="auto">When a playbook host has the roles <code class="notranslate">example_1</code> and <code class="notranslate">example_2</code> the following is executed:</p>
<ol dir="auto">
<li><code class="notranslate">dependency_1</code> (for <code class="notranslate">dependency_2</code>)</li>
<li><code class="notranslate">dependency_2</code> (for <code class="notranslate">example_1</code>)</li>
<li><code class="notranslate">dependency_1</code> (for <code class="notranslate">example_1</code>)</li>
<li><code class="notranslate">example_1</code></li>
<li><code class="notranslate">dependency_1</code> (for <code class="notranslate">dependency_2</code>)</li>
<li><code class="notranslate">dependency_1</code> (for <code class="notranslate">example_2</code>)</li>
<li><code class="notranslate">example_2</code></li>
</ol>
<p dir="auto">Step 5 is redundant and shouldn't run, as <code class="notranslate">dependency_2</code> is only run once and its dependencies should only be run once.</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="./site.yml
---
- hosts: example.com
  remote_user: user
  roles:
      - example_1
      - example_2"><pre class="notranslate"><span class="pl-s">./site.yml</span>
---
- <span class="pl-ent">hosts</span>: <span class="pl-s">example.com</span>
  <span class="pl-ent">remote_user</span>: <span class="pl-s">user</span>
  <span class="pl-ent">roles</span>:
      - <span class="pl-s">example_1</span>
      - <span class="pl-s">example_2</span></pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="./roles/example_{1,2}/meta/main.yml
---
dependencies:
    - role: dependency_2
    - role: dependency_1"><pre class="notranslate"><span class="pl-s">./roles/example_{1,2}/meta/main.yml</span>
---
<span class="pl-ent">dependencies</span>:
    - <span class="pl-ent">role</span>: <span class="pl-s">dependency_2</span>
    - <span class="pl-ent">role</span>: <span class="pl-s">dependency_1</span></pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="./roles/dependency_1/meta/main.yml
---
allow_duplicates: yes"><pre class="notranslate"><span class="pl-s">./roles/dependency_1/meta/main.yml</span>
---
<span class="pl-ent">allow_duplicates</span>: <span class="pl-s">yes</span></pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="./roles/dependency_2/meta/main.yml
---
dependencies:
    - role: dependency_1"><pre class="notranslate"><span class="pl-s">./roles/dependency_2/meta/main.yml</span>
---
<span class="pl-ent">dependencies</span>:
    - <span class="pl-ent">role</span>: <span class="pl-s">dependency_1</span></pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="./roles/{example_1,example_2,dependency_1,dependency_2}/tasks/main.yml
---
- name: display role
  debug:
    msg: this is role {{ role_path }}"><pre class="notranslate"><span class="pl-s">./roles/{example_1,example_2,dependency_1,dependency_2}/tasks/main.yml</span>
---
- <span class="pl-ent">name</span>: <span class="pl-s">display role</span>
  <span class="pl-ent">debug</span>:
    <span class="pl-ent">msg</span>: <span class="pl-s">this is role {{ role_path }}</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook site.yml

PLAY [example.com] ***************************************************

TASK [setup] *******************************************************************
ok: [example.com]

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_1&quot;
}

TASK [dependency_2 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_2&quot;
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_1&quot;
}

TASK [example_1 : display role] ************************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/example_1&quot;
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_1&quot;
}

TASK [example_2 : display role] ************************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/kyle/user/ansible/roles/example_2&quot;
}

PLAY RECAP *********************************************************************
example.com      : ok=8    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">$ ansible-playbook site.yml

PLAY [example.com] ***************************************************

TASK [setup] *******************************************************************
ok: [example.com]

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_1"
}

TASK [dependency_2 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_2"
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_1"
}

TASK [example_1 : display role] ************************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/example_1"
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_1"
}

TASK [example_2 : display role] ************************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/kyle/user/ansible/roles/example_2"
}

PLAY RECAP *********************************************************************
example.com      : ok=8    changed=0    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="$ ansible-playbook site.yml

PLAY [example.com] ***************************************************

TASK [setup] *******************************************************************
ok: [example.com]

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_1&quot;
}

TASK [dependency_2 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_2&quot;
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_1&quot;
}

TASK [example_1 : display role] ************************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/example_1&quot;
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_1&quot;
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/user/ansible/roles/dependency_1&quot;
}

TASK [example_2 : display role] ************************************************
ok: [example.com] =&gt; {
    &quot;msg&quot;: &quot;this is role /home/kyle/user/ansible/roles/example_2&quot;
}

PLAY RECAP *********************************************************************
example.com      : ok=8    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">$ ansible-playbook site.yml

PLAY [example.com] ***************************************************

TASK [setup] *******************************************************************
ok: [example.com]

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_1"
}

TASK [dependency_2 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_2"
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_1"
}

TASK [example_1 : display role] ************************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/example_1"
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_1"
}

TASK [dependency_1 : display role] *********************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/user/ansible/roles/dependency_1"
}

TASK [example_2 : display role] ************************************************
ok: [example.com] =&gt; {
    "msg": "this is role /home/kyle/user/ansible/roles/example_2"
}

PLAY RECAP *********************************************************************
example.com      : ok=8    changed=0    unreachable=0    failed=0
</code></pre></div>