<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">Ansible setup module.</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">ansible 2.2.2.0<br>
config file = /etc/ansible/ansible.cfg<br>
configured module search path = Default w/o overrides</p>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Control: CentOS 7.3<br>
Target: CentOS 7.3</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When gathering facts for a host with a high open file limit setting, fact gathering can take a long time. This is exacerbated on systems with many network interfaces. On a system with an open file limit of 1048576 and ~50 network interfaces (mostly virtual), fact gathering takes in excess of 20 seconds.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Set the open file limit to a high value:</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: all
  become: yes
  tasks:
  - name: increase file descriptor limit
    copy:
      dest: /etc/security/limits.d/99-nofile.conf
      content: |
        root soft nofile 1048576
        root hard nofile 1048576"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">become</span>: <span class="pl-s">yes</span>
  <span class="pl-ent">tasks</span>:
  - <span class="pl-ent">name</span>: <span class="pl-s">increase file descriptor limit</span>
    <span class="pl-ent">copy</span>:
      <span class="pl-ent">dest</span>: <span class="pl-s">/etc/security/limits.d/99-nofile.conf</span>
      <span class="pl-ent">content</span>: <span class="pl-s">|</span>
<span class="pl-s">        root soft nofile 1048576</span>
<span class="pl-s">        root hard nofile 1048576</span></pre></div>
<p dir="auto">Gather facts:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: all
  become: yes
  gather_facts: yes"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">become</span>: <span class="pl-s">yes</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-s">yes</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Facts are gathered in a reasonable time.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Facts took a long time to be gathered.</p>
<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">setup</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>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Linux</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">On some of my linux cluster servers, I have quite large max-open-files configuration (for some practical need), like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    $ulimit -n
    655360"><pre class="notranslate"><code class="notranslate">    $ulimit -n
    655360
</code></pre></div>
<p dir="auto">And ansible playbook's setup stage takes more than one minutes.</p>
<p dir="auto"><code class="notranslate">    time ansible -vvvv &lt;any host&gt; -m setup</code></p>
<p dir="auto">use <code class="notranslate">strace -f python /home/admin/.ansible/tmp/ansible-tmp-1493734939.34-186220473132806/setup</code>, I can see that when forking commands it's closing all fds until <code class="notranslate">os.sysconf('SC_OPEN_MAX')</code>, which cost lots of time。</p>
<p dir="auto">Since that is python's subprocess implementation behavior, for testing I hacked <code class="notranslate">build_module_command</code> in <code class="notranslate">ansible/plugins/shell/__init__.py</code> like this: <code class="notranslate">cmd_parts = ['ulimit -n 1024;', env_string.strip(), shebang.replace("#!", "").strip(), cmd]</code>, setup will only take less than 2 seconds.</p>
<p dir="auto">Any good idea? Or just should never config such large max-open-files at OS scope?</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=""><pre class="notranslate"></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate">
</code></pre></div>