False positive detection of k=v syntax

I’m getting this inside of a set_fact variable setting:

The offending line appears to be:

        gnome_dbus_env: '{{ "DBUS_SESSION_BUS_ADDRESS" + "=" + unix:path=/run/user/997/bus" }}'
                                                          ^ here

There appears to be both 'k=v' shorthand syntax and YAML in this task. Only one syntax may be used.

As you can see, I have tried to do some machinations to make this not be detected as the “k=v” shorthand with no luck. Is there a way to do this?

% ansible-playbook --version
ansible-playbook [core 2.18.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/boeckb/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.13/site-packages/ansible
  ansible collection location = /home/boeckb/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.13.7 (main, Aug 14 2025, 00:00:00) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] (/usr/bin/python3)
  jinja version = 3.1.6
  libyaml = True

You should provide a bit more context of what you’re actually doing (like: the concrete task that’s failing). It’s hard to see what went wrong from the information you provided.

I’m trying to set a variable as an argument to env in a role.

    - name: Setup GNOME extension information
      ansible.builtin.set_fact:
        gnome_user: 'gitlab-runner'
        gnome_extensions:
          - url: 'https://extensions.gnome.org/extension/4099/no-overview/'
            state: present
            installed: 'true'
        gnome_packages: []
        gnome_dbus_env: '{{ "DBUS_SESSION_BUS_ADDRESS" + "=" + unix:path=/run/user/997/bus" }}'

But it ends up tripping on this k=v legacy detection. Is there a way to set a variable to a value which matches that syntax?

The problem is the missing " before unix:path=.... This leads to various not very helpful error messages (depending on the ansible-core verison used). (I wasn’t able to get the message you provided with any verison I tried though…)

The line should be:

        gnome_dbus_env: '{{ "DBUS_SESSION_BUS_ADDRESS" + "=" + "unix:path=/run/user/997/bus" }}'

Yes, the missing quote is a problem…but I am still seeing the same error regardless.

I am using Fedora 42’s packaged ansible-playbook.

Please show us the complete error output. “The offending line appears to be:” introduces some diagnostic information/heuristic attempt to explain the error, but is not itself the actual error. For example, if I correct the problem that has been pointed out but deliberately break your task in a different way, I get:

Syntax Error while loading YAML.
  did not find expected ',' or '}'. while parsing a flow mapping
  in "<unicode string>", line 11, column 26
did not find expected ',' or '}'
  in "<unicode string>", line 11, column 55

The error appears to be in '/home/ec2-user/test.yml': line 11, column 55, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

        gnome_packages: []
        gnome_dbus_env: {{ "DBUS_SESSION_BUS_ADDRESS" + "=" + "unix:path=/run/user/997/bus" }}'
                                                      ^ here

We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

Why are you using mustaches at all? Isn’t this equivalent (after fixing the missing ") to:

gnome_dbus_env: 'DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/997/bus'

?

It was an attempt to deal with the (seemingly) more urgent error with an explanation rather than the first thing in the error message:

ERROR! 'become' is not a valid attribute for a IncludeRole

The error appears to be in '/home/boeckb/code/depot/group-kitware/proj-kwrobot/ci-deployments/src/ansible/roles/gitlab_runner/tasks/gitlab-runner/runners/x11-gnome.yml': line 22, column 50, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

        gnome_dbus_env: 'DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/997/bus'
                                                 ^ here

There appears to be both 'k=v' shorthand syntax and YAML in this task. Only one syntax may be used.

I think I was distracted by the attempt to explain the error and missed the “root” error (especially since it was on a completely different action).

Removing the become: true on the include_role bit works, but then fails because I need to activate become for the role…which is possible from the playbook-level. I was ending up having to become: true on pretty much everything in the role I thought I could factor it out, but that seems like a pipe dream :frowning: .

You have options. You can use apply with include_role to apply keywords to the included tasks, or you can use a block inside the role to apply become to all of the tasks at once.

(You can also put the include_role: inside a block: and then the tasks will inherit the block’s settings, but that’s the least obvious way to approach it.)

What you can’t do is use become directly on include_role, because it’s impossible for this task to run in an elevated context; it always runs with exactly the permissions of the main ansible-playbook process because it’s an internal part of that process.

Indeed. Thanks, this worked.