Repository: ansible/ansible

Issue:
ansible-pull shallow option
##### Issue Type:

Fetaure Request
##### Ansible Version:

ansible 1.7
##### Environment:

Ubuntu 14.04
##### Summary:

The ansible-pull command should have a switch to enable/disable shallow clone/pull of the git repository (... -m git -a "... depth=1"). In most cases there is absolutly no need to have the complete commit history on the client.

Shallow shoud be standard.
##### Steps To Reproduce:

None
##### Expected Results:

Pull a shallow copy of the git repository
##### Actual Results:

None so far



Discussion:
I agree this is wise, probably should just do it by default without the option to get the history, and that would be fine.

I was thinking even a git archive would be a better option, but make it
configurable, as there might be a case in which the ansible-pull client
will update it's own repo and push it back (yes sounds crazy).​

Code investigation reveals these relevant lines (166-174):

```
if options.checkout:
    repo_opts += ' version=%s' % options.checkout
path = utils.plugins.module_finder.find_plugin(options.module_name)
if path is None:
    sys.stderr.write("module '%s' not found.\n" % options.module_name)
    return 1
cmd = 'ansible all -i "%s" %s -m %s -a "%s"' % (
        inv_opts, base_opts, options.module_name, repo_opts
        )
```

So ansible allows to choose your cvs module of choice. There are two Problems:
1. Is off topic: `version` is not a valid option for hg and svn, which should be probably `revision` in this case (will file issue on this later)
2. I don't know exactly how bzr, hg and svn work. By that I mean: I don't know if they pull the whole commit history. As far as I remember svn doesn't. But with hg and bzr I really don't know. The ansible modules hg and bar seem to not offer an option similar to gits depth.

Since svn does not pull the whole history one should probably keep it consistent and really only do a shallow copy in git (and bzr/hg?) and not offer a switch to enable deep copy.

Thoughts?

Regarding git archive: If I do an ansible-pull I really just want to have access to all the data in the repo and execute a playbook. Using git archive would defeat the purpose. This and the thing with the push back should IMHO be something which should not be in ansible-pull, but probably in a playbook.

Got archive is basically an export w/o any version control. Perfect for
those that just want the data. Only issue I see is the tar format. Other
VCS also have "export to filesystem".

Last I looked, svn does copy the repo locally, just not to your working
directory (but its been a while since I've used it and I really preferred
the svk wrapper).

Brian Coca


Resolving patch:
diff --git a/lib/ansible/cli/pull.py b/lib/ansible/cli/pull.py
--- a/lib/ansible/cli/pull.py
+++ b/lib/ansible/cli/pull.py
@@ -80,6 +80,8 @@ def parse(self):
             help='directory to checkout repository to')
         self.parser.add_option('-U', '--url', dest='url', default=None,
             help='URL of the playbook repository')
+        self.parser.add_option('--full', dest='fullclone', action='store_true',
+            help='Do a full clone, instead of a shallow one.')
         self.parser.add_option('-C', '--checkout', dest='checkout',
             help='branch/tag/commit to checkout.  ' 'Defaults to behavior of repository module.')
         self.parser.add_option('--accept-host-key', default=False, dest='accept_host_key', action='store_true',
@@ -155,6 +157,10 @@ def run(self):
             if self.options.verify:
                 repo_opts += ' verify_commit=yes'
 
+            if not self.options.fullclone:
+                repo_opts += ' depth=1'
+
+
         path = module_loader.find_plugin(self.options.module_name)
         if path is None:
             raise AnsibleOptionsError(("module '%s' not found.\n" % self.options.module_name))


Test patch: