# Issue with 'when' conditional

**URL:** <https://forum.ansible.com/t/issue-with-when-conditional/25580>\
**Category:** Ansible Project\
**Created:** [September 22, 2017, 6:19pm UTC](https://forum.ansible.com/t/issue-with-when-conditional/25580 "2017-09-22T18:19:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://forum.ansible.com/u/Dave)\
**Post date:** [September 22, 2017, 6:19pm UTC](https://forum.ansible.com/t/issue-with-when-conditional/25580/1 "2017-09-22T18:19:31Z")

</div>

Hi,

I keep getting errors related to my ‘when’ conditionals in my following playbook:

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 22, 2017, 11:13pm UTC](https://forum.ansible.com/t/issue-with-when-conditional/25580/2 "2017-09-22T23:13:56Z")

</div>

conditionals apply to tasks, not vars\_prompt, which is not a task.

---

<div class="post-metadata">

**Author:** ![Dave](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@Dave](https://forum.ansible.com/u/Dave)\
**Post date:** [September 25, 2017, 4:22pm UTC](https://forum.ansible.com/t/issue-with-when-conditional/25580/3 "2017-09-25T16:22:11Z")

</div>

Hi Brian,

Thanks for the reply. After error testing, I commented out the conditional in vars\_prompt and reinserted it right after the task command, however it’s not liking the logic in my when-statement. Do you happen to know where I’m running into an error? I’m trying to add an exception to prevent the script from running if a user specifies the wrong account to delete such as ‘root’.

I took out the quotes and brackets from the remove\_user variable, but after running the playbook kicked back this message:

ERROR! Syntax Error while loading YAML.

The offending line appears to be:

command: “userdel {{ user\_to\_remove }}”  
when: user\_to\_remove != “root”  
^ here

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [September 25, 2017, 4:34pm UTC](https://forum.ansible.com/t/issue-with-when-conditional/25580/4 "2017-09-25T16:34:36Z")

</div>

when is a 'task' keyword, there you are making it an option for the  
command module, unindent.

- command: "userdel {{ user\_to\_remove }}"  
&nbsp;&nbsp;when: user\_to\_remove != "root"

also i recommend using the 'user' module instead.
