Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying --diff for ansible-pull #37645

Merged
merged 1 commit into from
Aug 28, 2018
Merged

Conversation

debugloop
Copy link
Contributor

SUMMARY

The ansible-pull command does not support the --diff (and --syntax-check) flags. This is due to the fact that the PullCLI parsing does not include the general check_opts CLI flag group which contains the two flags in question, as well as the --check flag. The check_opts group was propably left out due to a conflict between the ansible-pull specific --checkout/-C flag and the --check/-C flag which is part of the default CLI. Instead, the --check flag was added manually to the ansible-pull CLI parser, without its shorthand -C.

This PR does the same for the --diff and --syntax-check flags, and also adds comments describing the rationale behind adding these three manually (and without their shorthand versions).

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ansible-pull

ANSIBLE VERSION
ansible 2.6.0
  config file = None
  configured module search path = [u'/home/danieln/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/danieln/.virtualenvs/ansible-dev/lib/python2.7/site-packages/ansible-2.6.0-py2.7.egg/ansible
  executable location = /home/danieln/.virtualenvs/ansible-dev/bin/ansible
  python version = 2.7.14 (default, Jan  5 2018, 10:41:29) [GCC 7.2.1 20171224]
ADDITIONAL INFORMATION

The change works as expected. Running ansible-pull --diff -U git@github.com:debugloop/test-playbook.git test.yml on my machine yields the following results. The playbook can be viewed in said repo, but it is just a copy to a tmpfile with static content.

Before:

Usage: ansible-pull -U <repository> [options] [<playbook.yml>]

ansible-pull: error: no such option: --diff

After:

Starting Ansible Pull at 2018-03-20 15:52:06
/home/danieln/.virtualenvs/ansible-dev/bin/ansible-pull --diff -U git@gitlab.com:danieln/test-playbook.git test.yml
 [WARNING]: Could not match supplied host pattern, ignoring: icemark
localhost | SUCCESS => {
    "after": "09151533adff4ec72cac060c03c00bce1bfe8a90", 
    "before": "09151533adff4ec72cac060c03c00bce1bfe8a90", 
    "changed": false, 
    "remote_url_changed": false
}
 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
 [WARNING]: No inventory was parsed, only implicit localhost is available
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
'all'
 [WARNING]: Could not match supplied host pattern, ignoring: icemark

PLAY [test] ************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [localhost]

TASK [test writing a file] *********************************************************************************************
--- before: /tmp/test.txt
+++ after: /home/danieln/.ansible/tmp/ansible-local-155702xmYGP/tmpmP6VBq
@@ -1,3 +1,5 @@
 blabla
+bloblo
 blibli
+bleble
 blublu

changed: [localhost]

PLAY RECAP *************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0

@ansibot ansibot added feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:core This issue/PR relates to code supported by the Ansible Engineering Team. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 20, 2018
@webknjaz webknjaz removed the needs_triage Needs a first human triage before being processed. label Mar 20, 2018
@webknjaz
Copy link
Member

!component =lib/ansible/cli/pull.py

@debugloop
Copy link
Contributor Author

@webknjaz can you rerun the CI? I don't think the failure has to do with my changes, some test says Connection failure: ('The read operation timed out',) for some aws domain.

@mattclay
Copy link
Member

@debugloop I've restarted CI.

@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Mar 23, 2018
@ansibot
Copy link
Contributor

ansibot commented Mar 26, 2018

@debugloop this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibot ansibot added merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Mar 26, 2018
@ansibot ansibot removed merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Mar 26, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 4, 2018
@debugloop
Copy link
Contributor Author

Sorry to bother you guys, but it's been a month. What can I do to help get this approved? Anything you need from my side?

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")
self.parser.add_option('--syntax-check', dest='syntax', action='store_true',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure syntax check makes any sense in this context, why do it via pull? the playbook should be checked by ansible-playbook, using pull as a proxy for a check seems contrived.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. This change works around the Check CLI Option Group being blocked by the -C flag being already present in the ansible-pull specifig flags. I was originally going for the --diff option, but ended up including all flags from the check group. I can remove it of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the syntax checking option from this PR and used the opportunity to squash my commits and rebase to latest devel.

@debugloop debugloop force-pushed the devel branch 2 times, most recently from dcba8d8 to db52564 Compare April 24, 2018 13:40
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 24, 2018
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")
self.parser.add_option("--diff", default=C.DIFF_ALWAYS, dest='diff', action='store_true',
help="when changing (small) files and templates, show the differences in those files; works great with --check")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tempted to say just use check_opts=True and remove syntax check afterward with remove_option (we do this in ansible-inventory).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did that, we'd have to remove --check too and and re-add it without it's shorthand -C? Instead of check_opts=False with two adds we'd end up with a True and two removals and one re-add. I suppose it would reduce the number of duplicate help strings by one. You prefer the second option? Then I'll invert the current PR to do it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it were not for the -C i would not say 'tempted' but actually request it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll consider this merge-ready then.

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Apr 24, 2018
@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label May 3, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 11, 2018
@ansibot ansibot added the affects_2.6 This issue/PR affects Ansible v2.6 label May 19, 2018
@debugloop
Copy link
Contributor Author

Hello @dagwieers , sorry for bugging you but this seems to be waiting for your review. It's been a while and I've rebased the PR with the latest devel again. I guess this feature won't make 2.6 now that RCs have been released?

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jun 11, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jun 20, 2018
@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Jul 22, 2018
@hExPY
Copy link

hExPY commented Aug 28, 2018

+1 please merge :)

@dagwieers dagwieers removed their request for review August 28, 2018 10:58
@dagwieers
Copy link
Contributor

@debugloop That's easily fixed ;-) Although I don't think this was the blocking issue...

@dagwieers
Copy link
Contributor

dagwieers commented Aug 28, 2018

@bcoca Can this be merged for v2.7 ?

Update: Maybe I'll put it on the core meeting agenda instead.

@bcoca
Copy link
Member

bcoca commented Aug 28, 2018

!rebuild_merge

@bcoca bcoca merged commit edaa0b5 into ansible:devel Aug 28, 2018
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 feature This issue/PR relates to a feature request. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants