# if file exist condition to execute action

**URL:** <https://forum.ansible.com/t/if-file-exist-condition-to-execute-action/11862>\
**Category:** Ansible Project\
**Created:** [September 5, 2012, 10:30am UTC](https://forum.ansible.com/t/if-file-exist-condition-to-execute-action/11862 "2012-09-05T10:30:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Vito\_Moscarito](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@Marco\_Vito\_Moscarito](https://forum.ansible.com/u/Marco_Vito_Moscarito)\
**Post date:** [September 5, 2012, 10:30am UTC](https://forum.ansible.com/t/if-file-exist-condition-to-execute-action/11862/1 "2012-09-05T10:30:05Z")

</div>

Hello,  
&nbsp;&nbsp;I knoww is possible execute a action only if some file don't not  
exist using creates param, eg:

- name: activate apache2 modules  
&nbsp;&nbsp;action: command /usr/sbin/a2enmod $item  
creates=/etc/apache2/mods-enabled/$item.load  
&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;- actions  
&nbsp;&nbsp;&nbsp;&nbsp;- fastcgi  
&nbsp;&nbsp;&nbsp;&nbsp;- alias

is also possibile execcute action only if file exist?  
Eg:

- name: disable apache2 default websites  
&nbsp;&nbsp;action: command /usr/sbin/a2dissite $item  
remove=/etc/apache2/sites-enabled/$item  
&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;- default  
&nbsp;&nbsp;&nbsp;&nbsp;- default-ssl

And the task will be execute only if file  
/etc/apache2/sites-enabled/$item exist.

If is not possibile i think will be a nice feature fo ansible 0.8 😉

Bye  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marco

---

<div class="post-metadata">

**Author:** ![Marco\_Vito\_Moscarito](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@Marco\_Vito\_Moscarito](https://forum.ansible.com/u/Marco_Vito_Moscarito)\
**Post date:** [September 5, 2012, 11:11am UTC](https://forum.ansible.com/t/if-file-exist-condition-to-execute-action/11862/2 "2012-09-05T11:11:37Z")

</div>

Hello,  
&nbsp;&nbsp;really reactive community 😃

\* [https://github.com/ansible/ansible/pull/999](https://github.com/ansible/ansible/pull/999)  
\* [https://github.com/ansible/ansible/pull/1000](https://github.com/ansible/ansible/pull/1000)

Bye  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marco
