<p dir="auto">I have a simple file at /etc/foo.txt. The file contains the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#bar"><pre class="notranslate"><code class="notranslate">#bar
</code></pre></div>
<p dir="auto">I have the following ansible playbook task to uncomment the line above:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: test lineinfile
  lineinfile: backup=yes state=present dest=/etc/foo.txt
              regexp='^#bar'
              line='bar'"><pre class="notranslate"><code class="notranslate">- name: test lineinfile
  lineinfile: backup=yes state=present dest=/etc/foo.txt
              regexp='^#bar'
              line='bar'
</code></pre></div>
<p dir="auto">When I first run ansible-playbook, the line gets uncommented and the /etc/foo.txt now contains the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="bar"><pre class="notranslate"><code class="notranslate">bar
</code></pre></div>
<p dir="auto">However, if I run ansible-playbook again, I get the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="bar
bar"><pre class="notranslate"><code class="notranslate">bar
bar
</code></pre></div>
<p dir="auto">If I run it yet again, then the /etc/foo.txt file will look like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="bar
bar
bar"><pre class="notranslate"><code class="notranslate">bar
bar
bar
</code></pre></div>
<p dir="auto">I believe these duplications of lines are a bug.</p>
<p dir="auto">Happens on ansible-playbook 1.3.3 and 1.2.2.</p>
<p dir="auto">Roles do not use their variable definitions when actvated via the role dependency mechanism.</p>
<ul dir="auto">
<li>ansible 1.4 -devel <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/214b0b052c3d54b58a531b0f7fb401ec3c0229f5/hovercard" href="https://github.com/ansible/ansible/commit/214b0b052c3d54b58a531b0f7fb401ec3c0229f5"><tt>214b0b0</tt></a></li>
</ul>
<h1 dir="auto">Description</h1>
<ol dir="auto">
<li>alpha role depends on beta role</li>
<li>Each role provides a unique value for a variable named 'port' /vars/main.yml</li>
<li>When beta role is executed (aka <strong>"active"</strong>) via the role dependency mechanism, the role uses variable definitions from alpha role instead of its own definitions (roles/beta/vars/main.yml).</li>
<li>It has been noted that active roles use their variable definitions [unless higher precedent variables are passed via --extra-vars, or variable definitions in the base playbook]
<ul dir="auto">
<li>"... within a role, the variables in roles/y/vars/main.yml are guaranteed to be applied to that specific role, just as if they were parameters explicitly passed to the role." ( <a href="https://groups.google.com/d/msg/ansible-project/0JIrNlnRXuI/tx1-inKYoUQJ" rel="nofollow">https://groups.google.com/d/msg/ansible-project/0JIrNlnRXuI/tx1-inKYoUQJ</a> )</li>
</ul>
</li>
</ol>
<h1 dir="auto">Demonstration</h1>
<p dir="auto"><a href="https://github.com/briceburg/ansible-variable-scoping/tree/master/simple_vars">https://github.com/briceburg/ansible-variable-scoping/tree/master/simple_vars</a></p>