# Conditional doesn't work as expected

**URL:** <https://forum.ansible.com/t/conditional-doesnt-work-as-expected/12391>\
**Category:** Ansible Project\
**Created:** [February 20, 2013, 9:38am UTC](https://forum.ansible.com/t/conditional-doesnt-work-as-expected/12391 "2013-02-20T09:38:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/j/48db29/32.png) [@James\_Nguyen](https://forum.ansible.com/u/James_Nguyen)\
**Post date:** [February 20, 2013, 9:38am UTC](https://forum.ansible.com/t/conditional-doesnt-work-as-expected/12391/1 "2013-02-20T09:38:57Z")

</div>

Here’s a snippet of a task I’m trying to run:

# TODO: ignore\_errors because we don’t know why this even executes when ${shell\_accounts} is not set

- authorized\_key: user=${item} key=‘$FILE(${playbook\_files\_private}/keys/${item}\_id\_rsa.pub)’  
with\_items: ${shell\_accounts}  
when\_set: ${shell\_accounts}  
ignore\_errors: yes  
tags:
- keys.user

First off I tried to use when\_set to test if the variable is there. That conditional should be false and ignore the task, but it doesn’t. Then I even went to put a hack to ignore errors and move on but my playbook gets aborted still. I’m using the latest pull as of a few minutes of this post.

Result of $ ansible-playbook -i “[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com),” /etc/ansible/strategybooks/base.yml --extra-vars “[hosts=lamp5.cf5.kernelfire.com](http://hosts=lamp5.cf5.kernelfire.com)”:

PLAY [Base Playbook] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)]

PLAY [Proxy Playbook] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [user name=root password=$root\_passwd state=present] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)]

TASK: [template src= dest=/root/.bashrc owner=root group=root mode=0644] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)]

TASK: [template src= dest=/root/.bash\_profile owner=root group=root mode=0644] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)]

TASK: [template src= dest=/root/.bash\_logout owner=root group=root mode=0644] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)]

PLAY [Proxy Playbook] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [template dest=/etc/motd] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)]

PLAY [Proxy Playbook] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK: [template dest=/root/.ssh/authorized\_keys] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)]

TASK: [file dest=/home/ state=directory owner= group=users mode=0700] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)] =\> (item=${shell\_accounts})

TASK: [authorized\_key user= key=‘$FILE(${playbook\_files\_private}/keys/${item}\_id\_rsa.pub)’] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com)] =\> /etc/ansible/strategybooks/files\_private/keys/${shell\_accounts}\_id\_rsa.pub does not exist

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[lamp5.cf5.kernelfire.com](http://lamp5.cf5.kernelfire.com) : ok=7 changed=5 unreachable=1 failed=0

Looks like I’m doing something wrong?
