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?
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.
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…)
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:
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 .
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.