fix(php): accept short names in php_extensions_custom - #1679
Open
faisalahammad wants to merge 1 commit into
Open
fix(php): accept short names in php_extensions_custom#1679faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
Lets users write a plain list of short names in group_vars/all/main.yml:
php_extensions_custom:
- soap
- gd
Each entry expands to "php<version>-<name>": "<apt_package_state>" and
merges into php_extensions_default alongside the existing dict form, which
is still accepted unchanged.
The normalization lives in a small php_extensions filter so the shape
decision is in one place. The verify task in roles/common now checks
mapping for the other package vars and accepts mapping or non-string
sequence for php_extensions_custom.
Fixes roots#1666
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lets users write a plain list of short names in
php_extensions_custominstead of the verbosephp{{ php_version }}-<name>dict form. The legacy dict form is still accepted.Fixes #1666
Changes
roles/php/defaults/main.yml
Before:
After:
Why:
combine()needs a dict on the right side. A newphp_extensionsfilter coerces list input to{php<version>-<name>: <state>}and passes dict input through unchanged.lib/trellis/plugins/filter/filters.py
After:
Why: Single source of truth for the list vs dict shape decision.
roles/common/tasks/main.yml
Before: one
package_varsdict, all entries checked withrejectattr('value', 'mapping').php_extensions_customwas treated as dict-only.After: split into
package_vars_dict_only(mapping check) andpackage_vars_list_or_dict(mapping OR non-string sequence). The wrong-format list is the union of both wrong-key sets, so a string or int input tophp_extensions_customis still rejected.Why:
is sequencein Jinja2 is also true for strings, so the new predicate computes the valid-key set explicitly.Testing
Test 1: list form accepted
php_extensions_custom: [soap, gd]ingroup_vars/all/main.yml.pytest -q -ra tests/templates.Result: 6 new tests in
tests/templates/test_php_extensions_custom.pypass, plus the 9 pre-existing tests.Test 2: dict form still works
php_extensions_custom: { \"php{{ php_version }}-soap\": \"{{ apt_package_state }}\" }.pytest -q -ra tests/templatesandansible-playbook --syntax-check -e env=development server.yml.Result: same merged dict as before the change. Syntax check clean.
Test 3: bad input rejected
php_extensions_custom: \"oops\"(a bare string).Result: verify task fails with a message naming
php_extensions_customas a wrong-format variable.