<h1 dir="auto">ISSUE TYPE</h1>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ansible-pull</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.2.0"><pre class="notranslate"><code class="notranslate">ansible 2.1.2.0
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Not sure if this is a problem or just me doing it wrong, but I can not add a custom path for the known_hosts file for ansible-pull.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">By default, ansible-pull uses the known_hosts file located at <code class="notranslate">~/.ssh/known_hosts</code> but I should be able to add a custom one with <code class="notranslate">--ssh-common-args=UserKnownHostsFile=~/my_temporary_known_host</code><br>
Unfortunately, this setting is ignored by ansible-pull and the git checkout fails.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Starting Ansible Pull at 2016-10-26 15:06:29
/usr/local/mydir/bin/ansible-pull -i myinventory -U ssh://git@mygit -C master --private-key=mykey --ssh-common-args=UserKnownHostsFile=~/my_temporary_known_host
localhost | FAILED! =&gt; {
    &quot;changed&quot;: false, 
    &quot;failed&quot;: true, 
    &quot;msg&quot;: &quot;mygit has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module&quot;
}"><pre class="notranslate"><code class="notranslate">Starting Ansible Pull at 2016-10-26 15:06:29
/usr/local/mydir/bin/ansible-pull -i myinventory -U ssh://git@mygit -C master --private-key=mykey --ssh-common-args=UserKnownHostsFile=~/my_temporary_known_host
localhost | FAILED! =&gt; {
    "changed": false, 
    "failed": true, 
    "msg": "mygit has an unknown hostkey. Set accept_hostkey to True or manually add the hostkey prior to running the git module"
}
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">The <code class="notranslate">git</code> submodule which is used by <code class="notranslate">ansible-pull</code> when cloning the inventory repo is fixed to either initializing submodules recursively or not initializing submodules and doesn't support just initializing the first level of submodules in the repo.</p>
<p dir="auto">Use Case:</p>
<p dir="auto">I have thousands of IOT devices being managed using <code class="notranslate">ansible-pull</code>. Some SCM providers like Bitbucket have API limits and recursive cloning can be a problem here and also a scalability issue.</p>
<p dir="auto">If my <code class="notranslate">ansible-pull</code> inventory uses submodules for roles in <code class="notranslate">roles/</code> and each role itself uses submodules in its tests directory which mimics the inventory at <code class="notranslate">tests/roles/</code> used only for unit testing, then doing recursive submodule initialization is a huge cloning overhead that is ultimately not necessary.</p>
<p dir="auto">The difference in the number of clones in my case when I use 11 role submodules in the inventory repo is that non recursive submodule cloning causes 12 <code class="notranslate">git</code> clones, whereas recursive submodule cloning causes 52 <code class="notranslate">git</code> clones.</p>
<p dir="auto">When your IOT devices may be on internet connections of questionable quality, reducing the amount clones helps reduce the network traffic, load on SCM provider or self hosted instances, and reduce <code class="notranslate">ansible-pull</code> failures resulting from just trying to retrieve the inventory/roles.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Feature Idea</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ansible-pull<br>
git</p>
<h5 dir="auto">ADDITIONAL INFORMATION</h5>
<p dir="auto">My guess is that the current <code class="notranslate">git</code> module's behavior is modeled after <code class="notranslate">git-clone</code>'s behavior with its built in <code class="notranslate">--recurse-submodules</code> and <code class="notranslate">--shallow-submodules</code> options.</p>
<p dir="auto">However, in actual implementation, the <code class="notranslate">git</code> submodule is not using these <code class="notranslate">git-clone</code> options though, but instead using <code class="notranslate">git-submodule-update</code> <a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/source_control/git.py#L1198-L1209">recursive submodue init</a> except with <code class="notranslate">--init</code> and <code class="notranslate">--recursive</code> always fixed.</p>
<p dir="auto">Proposal:</p>
<p dir="auto">Extend the <code class="notranslate">git</code> module to add a <code class="notranslate">submodule_init</code> parameter (defaults to <code class="notranslate">yes</code> for backward compatibility) that controls whether or not submodules are initialized at all, and update the <code class="notranslate">submodule_update</code> method to only initialize recursively if the current <code class="notranslate">recursive</code> parameter is enabled. In addition, add <code class="notranslate">submodule_depth</code> parameter which is also used by <code class="notranslate">submodule_update</code> method to expose the depth and allow us to further reduce the clone size for better scalability.</p>
<p dir="auto">Extend the <code class="notranslate">ansible-pull</code> command to add flags for <code class="notranslate">--no-recurse-submodules</code> and <code class="notranslate">--no-submodule-init</code> and update the <a href="https://github.com/ansible/ansible/blob/devel/lib/ansible/cli/pull.py#L188-L206">options passed to git module</a> (the <code class="notranslate">submodule_depth</code> parameter can be set the same way as the <code class="notranslate">depth</code> parameter currently is, based on whether or not <code class="notranslate">--full</code> is provided).</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/bcoca/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/bcoca">@bcoca</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/sivel/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/sivel">@sivel</a> Thoughts on proposal and likelihood they would be accepted if I submitted PRs?</p>