# Does Ansible prevent 2 Tasks from modifying the same part of a system?(thus, Task 2 undoing what Task 1 did)

**URL:** <https://forum.ansible.com/t/does-ansible-prevent-2-tasks-from-modifying-the-same-part-of-a-system-thus-task-2-undoing-what-task-1-did/29530>\
**Category:** Ansible Project\
**Created:** [January 25, 2019, 2:23pm UTC](https://forum.ansible.com/t/does-ansible-prevent-2-tasks-from-modifying-the-same-part-of-a-system-thus-task-2-undoing-what-task-1-did/29530 "2019-01-25T14:23:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylvain\_Martel](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sylvain\_Martel](https://forum.ansible.com/u/Sylvain_Martel)\
**Post date:** [January 25, 2019, 2:23pm UTC](https://forum.ansible.com/t/does-ansible-prevent-2-tasks-from-modifying-the-same-part-of-a-system-thus-task-2-undoing-what-task-1-did/29530/1 "2019-01-25T14:23:24Z")

</div>

Hi,

We are new to using ansible, and I saw something while going through our early code that had me worried. I have CoderA and CoderB that are starting to create roles and tasks. In one Task, coderA adds IIS features, but coderB, in another role , also adds some IIS features in a Task, and also make sure other features are absent, but some of those features are installed by CoderA role. You can see the problem when both roles will be applied to the same machine.

In powershell DSC, there are failsafe in place to prevent this: When code tries to change something that was defined somewhere else, powershell will raise an error at the mof creation and prevent this. Is there some failsafe n Ansible too to prevent a task from undoing what another does? If not, what is the best way to avoid this?(code review won’t catch them all)

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 2, 2019, 12:15pm UTC](https://forum.ansible.com/t/does-ansible-prevent-2-tasks-from-modifying-the-same-part-of-a-system-thus-task-2-undoing-what-task-1-did/29530/2 "2019-02-02T12:15:50Z")

</div>

> Hi,
> 
> &nbsp;&nbsp;&nbsp;&nbsp;We are new to using ansible, and I saw something while going through  
> our early code that had me worried. I have CoderA and CoderB that are  
> starting to create roles and tasks. In one Task, coderA adds IIS features,  
> but coderB, in another role , also adds some IIS features in a Task, and  
> also make sure other features are absent, but some of those features are  
> installed by CoderA role. You can see the problem when both roles will  
> be applied to the same machine.

This is easily solved by having the code one place, many people uses a git repository for that job.  
And to add more security you can have code review before it get into production.

> In powershell DSC, there are failsafe in place to prevent this: When code  
> tries to change something that was defined somewhere else, powershell will  
> raise an error at the mof creation and prevent this. Is there some  
> failsafe n Ansible too to prevent a task from undoing what another does?  
> If not, what is the best way to avoid this?(code review won't catch them  
> all)

Ansible is declarative so the code you run says I want is to be configure like this and Ansible does what it's told and make the configuration that way.

So you need something outside of Ansible to make sure this doesn't happens.  
Code review and testing in different stages should catch this, if not you have some improvements to do in the work flow.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Martel](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sylvain\_Martel](https://forum.ansible.com/u/Sylvain_Martel)\
**Post date:** [February 2, 2019, 1:27pm UTC](https://forum.ansible.com/t/does-ansible-prevent-2-tasks-from-modifying-the-same-part-of-a-system-thus-task-2-undoing-what-task-1-did/29530/3 "2019-02-02T13:27:38Z")

</div>

Hi, thanks for the reply.

What you describe will help a bit, but is not error proof when you have thousands of line of code(and any infrastructure will reach that point quickly). Human make mistake, or are lazy, so eventually, 2 pieces of code that change the same setting will happen. One really nice thing about Powershell DSC is that it balks when you try to do something like that, so I was hoping it would be the same with ansible.
