Repository: ansible/ansible

Issue:
ansible-pull git options
Ansible Version: 1.9.2
Ansible Configuration: default
Environment: N/A

Summary:

Since 1.9 force=no is the default behaviour for git module and in case of using git from ansible playbooks this options is possible to change. However when running ansible-pull this option is impossible to change which may break the whole checkout on the machine running ansible-pull in case some file in the playbooks repo has a local change or smth else.
Could you add some option to ansible-pull that could be passed to the git module? Or make the git module read it's options from ansible.cfg.

Expected results:
ansible-pull is able to pass force=yes to the git module.

Actual results:
ansible-pull always uses git module with force=no which results in failing to run the playbook in case local modifications to the playbook repo exist.



Discussion:
In addition to montekki's report

It will be great to add "track_submodules" option to update submodules to latest ones.
With the check if there at least one submodule changed => we should get
`"changed": true`
state. 

May be you should add option to pass args directly to module, because it can be not only git.

@montekki Why do you have local modifications in your repo? Do you use git submodules? Maybe your problem in tracking submodules too? 

Seems it bug with track_submodules in git module.

Always when you get update on your submodule it goes to detached head state and parent repo get "Local modifications exist" state
When you try to update next time git repo with track_submodules you'll receive that local modifications exists, so we need force=yes
Even with force=yes head and remote sha in parent repo will be the same so git module won't update repo at all and of course submodules

Will be nice with https://github.com/ansible/ansible-modules-core/issues/1509

# Closing This Ticket

Hi!

We believe the above commit should resolve this problem for you. This will also be included in the next major release.

If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
- https://groups.google.com/forum/#!forum/ansible-project - for user questions, tips, and tricks
- https://groups.google.com/forum/#!forum/ansible-devel - for strategy, future planning, and questions about writing code

Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.

Thank you!


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
@@ -91,6 +91,11 @@ def parse(self):
         self.parser.add_option('--verify-commit', dest='verify', default=False, action='store_true',
             help='verify GPG signature of checked out commit, if it fails abort running the playbook.'
                  ' This needs the corresponding VCS module to support such an operation')
+        self.parser.add_option('--clean', dest='clean', default=False, action='store_true',
+            help='modified files in the working repository will be discarded')
+        self.parser.add_option('--track-subs', dest='tracksubs', default=False, action='store_true',
+            help='submodules will track the latest changes'
+                 ' This is equivalent to specifying the --remote flag to git submodule update')
 
         self.options, self.args = self.parser.parse_args(self.args[1:])
 
@@ -157,6 +162,12 @@ def run(self):
             if self.options.verify:
                 repo_opts += ' verify_commit=yes'
 
+            if self.options.clean:
+                repo_opts += ' force=yes'
+
+            if self.options.tracksubs:
+                repo_opts += ' track_submodules=yes'
+
             if not self.options.fullclone:
                 repo_opts += ' depth=1'
 


Test patch: