<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.5</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">npm module won't install a package if it is installed as another package's dependency</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="- name: Install less compiler, css minifier
  npm: name={{ item }}
  with_items:
    - less
    - clean-css"><pre class="notranslate">- <span class="pl-ent">name</span>: <span class="pl-s">Install less compiler, css minifier</span>
  <span class="pl-ent">npm</span>: <span class="pl-s">name={{ item }}</span>
  <span class="pl-ent">with_items</span>:
    - <span class="pl-s">less</span>
    - <span class="pl-s">clean-css</span></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">clean-css should be installed, as it will be if you run:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# npm install less clean-css"><pre class="notranslate"><span class="pl-c"><span class="pl-c">#</span> npm install less clean-css</span></pre></div>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">clean-css is not installed.</p>
<p dir="auto">This is because the npm module is misinterpreting the results of npm list. If the less package is installed, <code class="notranslate">npm list --json clean-css</code> returns:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;dependencies&quot;: {
    &quot;less&quot;: {
      &quot;version&quot;: &quot;1.7.0&quot;,
      &quot;from&quot;: &quot;less@&quot;,
      &quot;dependencies&quot;: {
        &quot;clean-css&quot;: {
          &quot;version&quot;: &quot;2.1.6&quot;,
          &quot;from&quot;: &quot;clean-css@2.1.x&quot;
        }
      }
    }
  }
}"><pre class="notranslate">{
  <span class="pl-ent">"dependencies"</span>: {
    <span class="pl-ent">"less"</span>: {
      <span class="pl-ent">"version"</span>: <span class="pl-s"><span class="pl-pds">"</span>1.7.0<span class="pl-pds">"</span></span>,
      <span class="pl-ent">"from"</span>: <span class="pl-s"><span class="pl-pds">"</span>less@<span class="pl-pds">"</span></span>,
      <span class="pl-ent">"dependencies"</span>: {
        <span class="pl-ent">"clean-css"</span>: {
          <span class="pl-ent">"version"</span>: <span class="pl-s"><span class="pl-pds">"</span>2.1.6<span class="pl-pds">"</span></span>,
          <span class="pl-ent">"from"</span>: <span class="pl-s"><span class="pl-pds">"</span>clean-css@2.1.x<span class="pl-pds">"</span></span>
        }
      }
    }
  }
}</pre></div>
<p dir="auto">The npm module interprets this to mean that clean-css is installed.</p>
<p dir="auto"><strong>Scenario</strong>:</p>
<p dir="auto">Trying to install <code class="notranslate">uglify-js</code> (globally) because I need the <em>uglifyjs</em> executable. Unfortunately the <code class="notranslate">npm</code> Ansible module won't install it because it's already listed as a dependency of another nodejs package (this other package is installed earlier in my playbook and I can't really move it). But when installed as dependency, it didn't get installed with the executable.</p>
<p dir="auto"><strong>Possible solutions</strong>:</p>
<ul dir="auto">
<li>A 'force' option to install regardless. But that's against idempotency I suppose.</li>
<li>Make the <code class="notranslate">npm</code> Ansible module aware if a package is installed at top-level or not and allow installation is the package to be installed is strictly a dependency.</li>
</ul>