# Ansible 2.0 Deprecation in "when:" conditional.

**URL:** <https://forum.ansible.com/t/ansible-2-0-deprecation-in-when-conditional/20199>\
**Category:** Ansible Project\
**Created:** [January 13, 2016, 4:44pm UTC](https://forum.ansible.com/t/ansible-2-0-deprecation-in-when-conditional/20199 "2016-01-13T16:44:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel\_Jimenez](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Manuel\_Jimenez](https://forum.ansible.com/u/Manuel_Jimenez)\
**Post date:** [January 13, 2016, 4:44pm UTC](https://forum.ansible.com/t/ansible-2-0-deprecation-in-when-conditional/20199/1 "2016-01-13T16:44:01Z")

</div>

Hi!

I have a role that clean my /etc/cron.d , /etc/cron.daily, etc… and installs new crons that I have defined in the role. For this duty I’ve do a simple but powerfull playbook but in version 2.0 instead of skeep a steep, I see a deprecation warning.

Example:

## LOOK IF PLACEHOLDER FILE EXISTS AND REGISTER IN A VAR

- stat:  
path=/etc/cron.d/placeholder  
register: placeholdercrond  
tags: [“cron.all”, “cron.d”]

## IF NOT EXISTS, LIST ALL FILES AND STORE THEM IN A VAR

- shell: ls -1 /etc/cron.d  
register: crond  
when: placeholdercrond.stat.exists == False  
tags: [“cron.all”, “cron.d”]

## DELETE EVERY FILE IF LAST COMMAND WHERE TRUE BECAUSE crond VAR HAS VALUES

- file:  
path=/etc/cron.d/{{ item }}  
state=absent  
with\_items: crond.stdout\_lines  
when: crond.changed == True  
tags: [“cron.all”, “cron.d”]

- WHEN NOT PLACEHOLDER FILE: PLAYBOOK RUN OK

- WHEN THERE IS A PLACEHOLDER FILE: PLAYBOOK SHOWS A DEPRECATION, FUTURE ERROR IN FILE MODULE

PLAY \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [cron : stat] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [testserver]

TASK [cron : command] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [testserver]

TASK [cron : file] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[DEPRECATION WARNING]: Skipping task due to undefined attribute, in the future this will be a fatal error.. This feature will be removed in a future release. Deprecation warnings can be disabled by setting  
deprecation\_warnings=False in ansible.cfg.

This is because {{ item }} is empty, but this steep should be skipped because the when: condition is not meeted.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Manuel\_Jimenez](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Manuel\_Jimenez](https://forum.ansible.com/u/Manuel_Jimenez)\
**Post date:** [January 13, 2016, 5:34pm UTC](https://forum.ansible.com/t/ansible-2-0-deprecation-in-when-conditional/20199/2 "2016-01-13T17:34:56Z")

</div>

I suggest to add an output when any task is skipped because of empy with\_ loop with a message like:

[skipped]: skipped due to no items

Cheers!
