# Run a role once and only once

**URL:** <https://forum.ansible.com/t/run-a-role-once-and-only-once/17270>\
**Category:** Ansible Project\
**Created:** [January 14, 2015, 6:45pm UTC](https://forum.ansible.com/t/run-a-role-once-and-only-once/17270 "2015-01-14T18:45:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matt/32/1267_2.png) [@matt](https://forum.ansible.com/u/matt)\
**Post date:** [January 14, 2015, 6:45pm UTC](https://forum.ansible.com/t/run-a-role-once-and-only-once/17270/1 "2015-01-14T18:45:30Z")

</div>

Hi,

I have a role that’s called from other roles via dependencies. I’m seeing the role run twice, as discussed at [https://groups.google.com/forum/#!searchin/ansible-project/role$20dependencies$20run$20twice/ansible-project/qoC1fVKEm7I/MWDl9ALo-KoJ](https://groups.google.com/forum/#!searchin/ansible-project/role$20dependencies$20run$20twice/ansible-project/qoC1fVKEm7I/MWDl9ALo-KoJ)

I’ve worked around this by adding the following as the last task of the role:

- set\_fact: myrole\_has\_run=true  
when: myrole\_has\_run is not defined

And then in the meta/defaults.yml:

dependencies:

- role: myrole  
when: myrole\_has\_run is not defined

Is there a native way of making sure a role only runs once?

Thanks.  
Matt
