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
Simplify and improve package name squashing #15657
Conversation
d6e0f5c
to
a8556be
Compare
I wanted to go one step further and make it configurable as shown in #12086 ignore |
a8556be
to
1430f2d
Compare
@bcoca, the tests broke on It would be good to get the fix for #15649 backported to 2.0 and 2.1. Looks like it can be trivially cherry-picked onto stable-2.1 and reasonably easily cherry-picked onto stable-2.0. |
Also, this is mislabelled feature_pull_request. |
Could we please merge this into devel, and not wait for 2.2, since this is a bugfix pull request, not a feature request. Currently in devel modules which use squashing of I tested this pull request on the latest devel and it worked like a charm. |
Okay, I cudgeled my brain and finally recalled the reason that we template the name field twice in the old code. Things like this are caught by the old code but not by the proposed code:
Templating the name field twice catches the fact that list_of_pkgs is templated to the same value in both instances of the loop. Simply comparing the templated name field to the original name field does not catch this case. |
I don't think that's a deal breaker, though. I don't think the problem being solved was in the double templating so we should be able to drop that portion back into the new code without issues (with a better comment as to why we're doing things that way). |
How does this new code handle things that aren't strings? For instance,
It looks like name will end up being
|
The old code only coped with strings - is that last use case actually a regression? |
if the new code puts the items together like that, it is a regression... The old code would have skipped squashing in that case. |
* Allow variables that contain a dict lookup * Squash names built from dictionary values e.g. ``` package: name="{{item.name}}-{{item.version}}" with_items: - name: hello version: 1.2.3 - name: goodbye version: 2.3.4 ``` now works the same as ``` package: name="{{item}}" with_items: - hello-1.2.3 - goodbye-2.3.4 ``` * Fix some erroneous test assumptions e.g. ``` package: name="{{pkg_mgr}}" with_items: - hello-1.2.3 - goodbye-2.3.4 ``` should just install a single package with the name pkg_mgr (in effect item is not a bound variable) Fixes ansible#15649 Reordered some tests to better reflect comments
Fixed quite a few breaking tests (mostly where the conditional evaluation resulted in True)
1430f2d
to
baf62cc
Compare
@abadger squashing now squashes lists of lists. I've "fixed" a bunch of tests where the test was broken for the results returned (usually because the squash happened where it wasn't before, and the conditional evaluation removed items) |
Okay, update -- will and I talked on IRC last night. I didn't think some of the test cases were right so I worked on those for a while and merged a new set today. The cleanups here don't pass the new tests so also decided to push a fix jsut for #15649. Those changes are in and cherry-picked to stable-2.1 and stable-2.0 branches. Aside from the tests, I think we still need to template the name field twice in order to catch whether it contains a loop_var or not. Checking against the original string wouldn't catch things like a non-loop-var being templated into name. when in doubt about the validity of squashing we should err on the side of safety and not squash. Squashing is really a dead-end feature now that every module that squashes has to take a list type (as users can just pass a list directly instead of having to use with_items to create their list). |
@willthames This PR was tested by travis-ci.org, which is no longer used. Please rebase your branch to trigger running of current tests. |
ISSUE TYPE
ANSIBLE VERSION
SUMMARY
Allow variables that contain a dict lookup
Squash names built from dictionary values e.g.
now works the same as
Fix some erroneous test assumptions e.g.
should just install a single package with the name
pkg_mgr
(in effectitem
is not a bound variable)Fixes #15649