Conditional message not working correctly

Hi all, I’m scratching my head on this one.

I am attempting to make a conditional message based on whether a variable value is 0 or not. Here’s what I have:

  • debug:
    msg:
  • “{{ ‘User is root’ if (user_id.stdout_lines == ‘0’) else not_root }}”

The user_id variable is basically just running the id -u command on the server. if it’s root, it’ll be 0, if it’s not root then it’ll be whatever their ID number is.
The issue I’m having is that even when the id -u returns 0, I’m still getting the ‘not_root’ variable passed into the output.

I am unable to get this to work so figured someone on here may be able to point me in the right direction?

Thanks in advance

stdout_lines is an array of the lines from stdout. The full content of stdout as a single string is in the variable stdout.

pretty sure what you need is

if (user_id.stdout == ‘0’)

You are a star!

I didn’t even think to use just standard stdout :frowning:

Thanks

Is it possible to even do something like this?

“{{not_root if user_id.stdout != ‘0’}}”

So it doesn’t return anything if the user is root?