<p dir="auto">when using multiple inventory files defining different groups for the same hosts, ansible adds the hosts multiple times to the inventory list.</p>
<p dir="auto">version: 1.4.4+dfsg-1 (from debian jessie)<br>
same problem with current devel <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/00b3f627ebb2b8e9cf743671a9ddd2d8d8c9fe45/hovercard" href="https://github.com/ansible/ansible/commit/00b3f627ebb2b8e9cf743671a9ddd2d8d8c9fe45"><tt>00b3f62</tt></a></p>
<p dir="auto">reproduce:</p>
<ul dir="auto">
<li>use files from <a href="https://gist.github.com/g-k-r/8599442">https://gist.github.com/g-k-r/8599442</a></li>
<li>run <strong>ansible all --list</strong></li>
<li>run <strong>ansible group2 --list</strong> and compare with <strong>ansible type2 --list</strong></li>
</ul>
<p dir="auto">actual output:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ ansible all --list
    www.google.com
    www.yahoo.com
    www.yahoo.com
$ ansible group2 --list
    www.yahoo.com
$ ansible type2 --list
    www.yahoo.com
    www.yahoo.com"><pre class="notranslate">$ ansible all --list
    www.google.com
    www.yahoo.com
    www.yahoo.com
$ ansible group2 --list
    www.yahoo.com
$ ansible type2 --list
    www.yahoo.com
    www.yahoo.com</pre></div>
<p dir="auto">note when the group is defined in both files like [type1] this does not happen.</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ ansible type1 --list
    www.google.com"><pre class="notranslate">$ ansible type1 --list
    www.google.com</pre></div>
<p dir="auto">expected output: <a href="http://www.yahoo.com" rel="nofollow">www.yahoo.com</a> shows up once only i.e.</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ ansible all --list
    www.google.com
    www.yahoo.com
$ ansible group2 --list
    www.yahoo.com
$ ansible type2 --list
    www.yahoo.com"><pre class="notranslate">$ ansible all --list
    www.google.com
    www.yahoo.com
$ ansible group2 --list
    www.yahoo.com
$ ansible type2 --list
    www.yahoo.com</pre></div>
<p dir="auto">additional information:</p>
<p dir="auto">to verify that tasks would actually be executed multiple times use</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ ansible all -m debug -a '&quot;msg=TEST {{inventory_hostname}}&quot;'
www.google.com | success &gt;&gt; {
    &quot;msg&quot;: &quot;TEST www.google.com&quot;
}

www.yahoo.com | success &gt;&gt; {
    &quot;msg&quot;: &quot;TEST www.yahoo.com&quot;
}

www.yahoo.com | success &gt;&gt; {
    &quot;msg&quot;: &quot;TEST www.yahoo.com&quot;
}"><pre class="notranslate">$ ansible all -m debug -a <span class="pl-s"><span class="pl-pds">'</span>"msg=TEST {{inventory_hostname}}"<span class="pl-pds">'</span></span>
www.google.com <span class="pl-k">|</span> success <span class="pl-k">&gt;&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>TEST www.google.com<span class="pl-pds">"</span></span>
}

www.yahoo.com <span class="pl-k">|</span> success <span class="pl-k">&gt;&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>TEST www.yahoo.com<span class="pl-pds">"</span></span>
}

www.yahoo.com <span class="pl-k">|</span> success <span class="pl-k">&gt;&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>TEST www.yahoo.com<span class="pl-pds">"</span></span>
}</pre></div>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">Current latest devel.  Also 1.6 and assorted versions in between.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible --version
ansible 1.8 (devel 2eda9a3a47) last updated 2014/10/10 18:43:36 (GMT +100)
  lib/ansible/modules/core: (detached HEAD 5af8d55b03) last updated 2014/10/10 18:43:44 (GMT +100)
  lib/ansible/modules/extras: (detached HEAD 681db4ce2c) last updated 2014/10/10 18:43:45 (GMT +100)
  v2/ansible/modules/core: (detached HEAD cb69744bce) last updated 2014/10/08 10:13:54 (GMT +100)
  v2/ansible/modules/extras: (detached HEAD 8a4f07eecd) last updated 2014/10/08 10:14:38 (GMT +100)"><pre class="notranslate"><code class="notranslate">$ ansible --version
ansible 1.8 (devel 2eda9a3a47) last updated 2014/10/10 18:43:36 (GMT +100)
  lib/ansible/modules/core: (detached HEAD 5af8d55b03) last updated 2014/10/10 18:43:44 (GMT +100)
  lib/ansible/modules/extras: (detached HEAD 681db4ce2c) last updated 2014/10/10 18:43:45 (GMT +100)
  v2/ansible/modules/core: (detached HEAD cb69744bce) last updated 2014/10/08 10:13:54 (GMT +100)
  v2/ansible/modules/extras: (detached HEAD 8a4f07eecd) last updated 2014/10/08 10:14:38 (GMT +100)
</code></pre></div>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Ansible run on Ubuntu 12.04.5 LTS.  Clients Centos 6.5 (the bug manifests locally and remotely).</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Ansible's 'copy' module has a parameter, 'content'.  Although jinja2 expansions in the content parameter appear to be supported, they don't work as expected, specifically they do not mimic the behaviour of the template module with the same content.  Quoting appears to be mangled in some cases, and ansible can be made to throw exceptions with others. A content value '{{x}}', where a var x is defined with quotes within, will not necessarily result in the quotes (and whitespace) being preserved.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">Create a playbook called 'test.yml':</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: quote mangling
  hosts: all

  vars:
    content: a=&quot;q &quot;

  tasks:
    - name: test copy
      action: copy
              content=&quot;{{content}}&quot;
              dest=/tmp/content"><pre class="notranslate"><code class="notranslate">
---
- name: quote mangling
  hosts: all

  vars:
    content: a="q "

  tasks:
    - name: test copy
      action: copy
              content="{{content}}"
              dest=/tmp/content
</code></pre></div>
<p dir="auto">You may also need an ansible_hosts like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="localhost"><pre class="notranslate"><code class="notranslate">localhost
</code></pre></div>
<p dir="auto">Then run ansible-playbook like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible-playbook -l localhost -c local test.yml"><pre class="notranslate"><code class="notranslate">ansible-playbook -l localhost -c local test.yml
</code></pre></div>
<p dir="auto">Output looks like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [quote mangling] ************************************************************* 

GATHERING FACTS *************************************************************** 
ok: [localhost]

TASK: [test copy] ************************************************************* 
ok: [localhost]

PLAY RECAP ******************************************************************** 
localhost                  : ok=2    changed=0    unreachable=0    failed=0   "><pre class="notranslate"><code class="notranslate">PLAY [quote mangling] ************************************************************* 

GATHERING FACTS *************************************************************** 
ok: [localhost]

TASK: [test copy] ************************************************************* 
ok: [localhost]

PLAY RECAP ******************************************************************** 
localhost                  : ok=2    changed=0    unreachable=0    failed=0   
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">The expected result is a file in /tmp/content containing this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="a=&quot;q &quot;"><pre class="notranslate"><code class="notranslate">a="q "
</code></pre></div>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">What I actually get in the file is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;a=&quot;q"><pre class="notranslate"><code class="notranslate">"a="q
</code></pre></div>
<p dir="auto">No trailing space; quotes have been re-inserted wrongly.</p>
<h5 dir="auto">Other cases</h5>
<p dir="auto">Remove the second quote in the var definition.  Ansible rejects the input:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [localhost] =&gt; error parsing argument string 'content=&quot;a=&quot;q&quot; dest=/tmp/content', try quoting the entire line."><pre class="notranslate"><code class="notranslate">fatal: [localhost] =&gt; error parsing argument string 'content="a="q" dest=/tmp/content', try quoting the entire line.
</code></pre></div>
<p dir="auto">I believe I managed to make ansible throw an exception with one variation, however I cannot reproduce that now; possibly dependent on the version of ansible.</p>