# Conditional message not working correctly

**URL:** <https://forum.ansible.com/t/conditional-message-not-working-correctly/28114>\
**Category:** Ansible Developer\
**Created:** [July 21, 2018, 8:37am UTC](https://forum.ansible.com/t/conditional-message-not-working-correctly/28114 "2018-07-21T08:37:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![email](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@email](https://forum.ansible.com/u/email)\
**Post date:** [July 21, 2018, 8:37am UTC](https://forum.ansible.com/t/conditional-message-not-working-correctly/28114/1 "2018-07-21T08:37:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ed\_C](https://avatars.discourse-cdn.com/v4/letter/e/c67d28/32.png) [@Ed\_C](https://forum.ansible.com/u/Ed_C)\
**Post date:** [July 21, 2018, 8:43am UTC](https://forum.ansible.com/t/conditional-message-not-working-correctly/28114/2 "2018-07-21T08:43:25Z")

</div>

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’)

---

<div class="post-metadata">

**Author:** ![email](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@email](https://forum.ansible.com/u/email)\
**Post date:** [July 21, 2018, 8:46am UTC](https://forum.ansible.com/t/conditional-message-not-working-correctly/28114/3 "2018-07-21T08:46:21Z")

</div>

You are a star!

I didn’t even think to use just standard stdout ☹

Thanks

---

<div class="post-metadata">

**Author:** ![email](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@email](https://forum.ansible.com/u/email)\
**Post date:** [July 21, 2018, 8:50am UTC](https://forum.ansible.com/t/conditional-message-not-working-correctly/28114/4 "2018-07-21T08:50:24Z")

</div>

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?
