Repository: ansible/ansible

Issue:
ansible-pull does not support check mode
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Feature Idea

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
ansible-pull

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
latest devel
```
ansible 2.4.0
  config file = None
  configured module search path = [u'/home/centos/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
none, just did pip install git+git://github.com/ansible/ansible.git@devel

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
CentOS 7.2

##### SUMMARY
<!--- Explain the problem briefly -->
ansible-pull does not appear to have any option to enable check mode or do a dry run.
One can write 'check_mode: yes' into the tasks but one should not have to change the tasks files to use check mode.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
'ansible-pull --help' does not show any check option.
Ideally it would have the same '--check' option as ansible-playbook has.

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
ansible-pull could be used with a check mode to test what changes would happen.
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
ansible-pull does not support check mode.

If you do try to use a '--check' option, there seems to be some option parsing that matches "checkout":

<!--- Paste verbatim command output between quotes below -->
```

$ sudo ansible-pull -U https://github.com/RaymiiOrg/Ansible-Pull-Example -v --full --check
Usage: ansible-pull -U <repository> [options] [<playbook.yml>]

ansible-pull: error: --checkout option requires an argument


```



Discussion:

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
@@ -107,6 +107,8 @@ def parse(self):
                                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.parser.add_option("--check", default=False, dest='check', action='store_true',
+                               help="don't make any changes; instead, try to predict some of the changes that may occur")
 
         # for pull we don't want a default
         self.parser.set_defaults(inventory=None)
@@ -243,6 +245,8 @@ def run(self):
             cmd += ' -l "%s"' % self.options.subset
         else:
             cmd += ' -l "%s"' % limit_opts
+        if self.options.check:
+            cmd += ' -C'
 
         os.chdir(self.options.dest)
 


Test patch: