Skip to content

Unquoted variables turns into !!null #4777

@konstruktoid

Description

@konstruktoid
Summary

If a variable is unquoted, {{ a_message }}, the result will be { { a_message: !!null "" }: !!null "" } after running ansible-lint.

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint 25.9.1.dev1 using ansible-core:2.20.0.dev0 ansible-compat:25.8.1 ruamel-yaml:0.18.15 ruamel-yaml-clib:0.2.12

uv pip install -U -r https://raw.githubusercontent.com/konstruktoid/ansible-role-hardening/refs/heads/master/requirements-upstream.txt

STEPS TO REPRODUCE
---
- name: Test Playbook
  hosts: localhost
  gather_facts: true
  vars:
    a_message: "At the gates"
  tasks:
    - name: Print a message
      debug:
        msg: {{ a_message }}
$ ansible-lint --fix ./test.yml
[WARNING]: Deprecation warnings can be disabled by setting `deprecation_warnings=False` in ansible.cfg.
[DEPRECATION WARNING]: Importing 'to_bytes' from 'ansible.module_utils._text' is deprecated. This feature will be removed from ansible-core version 2.24. Use ansible.module_utils.common.text.converters instead.
WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
WARNING  Listing 1 violation(s) that are fatal

Modified 1 file.
# Rule Violation Summary

  1 load-failure profile:min tags:core,unskippable

Failed: 1 failure(s), 0 warning(s) in 1 files processed of 1 encountered.
load-failure[runtimeerror]: ('Failed to load YAML file', PosixPath('test.yml')) (warning)
test.yml:1 while constructing a mapping
  in "<unicode string>", line 10, column 14
found unhashable key
  in "<unicode string>", line 10, column 15
---
- name: Test Playbook
  hosts: localhost
  gather_facts: true
  vars:
    a_message: "At the gates"
  tasks:
    - name: Print a message
      debug:
        msg: { { a_message: !!null "" }: !!null "" }
Desired Behavior

Quoted variable as in earlier versions.

Actual Behavior

See above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    newTriage required

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions