-
Story
-
Resolution: Done
-
Undefined
-
None
-
None
-
rhel-system-roles
-
0
-
False
-
False
-
-
None
-
None
-
Unspecified
-
Unspecified
-
Unspecified
Ansible 2.19 introduces some big changes
https://docs.ansible.com/ansible/devel/porting_guides/porting_guide_core_2.19.html
One big change is that data structures are no longer mutable by the use of python
methods such as `_setitem_`, `setdefault`, `update`, etc. in Jinja constructs.
Instead, items must use filters or other Jinja operations.
One common idiom is to mutate each element in a list. Since we cannot do this
"in-place" anymore, a common way to do this is:
```yaml
- name: Construct a new list from an existing list and mutate each element
set_fact:
__new_list: "{{ __new_list | d([]) + [mutated_item] }}"
loop: "{{ old_list }}"
mutated_item: "{{ some value based on item from old list }}"
- name: Reset original old list
set_fact:
old_list: "{{ __new_list }}"
```
Similarly with `dict` items:
```yaml
- name: Construct a new dict from an existing dict and mutate each element
set_fact:
__new_dict: "{{ __new_dict | d({}) | combine(mutated_item) }}"
loop: "{{ old_dict | dict2items }}"
mutated_item: "{{ {item.key: mutation of item.value}}}"
- name: Reset original old dict
set_fact:
old_dict: "{{ __new_dict }}"
```
Another big change is that a boolean expression in a `when` or similar construct
must be converted to a boolean - we cannot rely on the implicit evaluation in
a boolean context. For example, if `var` is some iterable, like a `dict`, `list`,
or `string`, you used to be able to evaluate an empty value in a boolean context:
```yaml
when: var # do this only if var is not empty
```
You now have to explicitly test for empty using `length`:
```yaml
when: var | length > 0 # do this only if var is not empty
```
These are the biggest changes. See the porting guide for others.
Signed-off-by: Rich Megginson <rmeggins@redhat.com>
-
- Summary by Sourcery
Refactor Jinja templates and set_fact usage to comply with Ansible 2.19’s immutability rules by replacing in-place data mutations and complex Jinja control flow with filter-based expressions and accumulation patterns.
Enhancements:
- Accumulate certificate_requests list via sequential set_fact calls instead of mutating original list in Jinja.
- Replace multi-line Jinja logic for __mssql_ha_is_primary with a concise expression using dict2items, selectattr, map, and boolean filters.
- Ensure __sqlcmd_cli path is constructed with explicit string conversion of __sqlcmd_ver to prevent type mismatches.
- clones
-
RHEL-106149 refactor: support ansible 2.19
-
- Closed
-
- links to
-
RHEA-2025:151622 Updating mssql role to 2.6.3