# Rollback in Ansible ?

**URL:** <https://forum.ansible.com/t/rollback-in-ansible/30324>\
**Category:** Ansible Project\
**Created:** [May 14, 2019, 9:54am UTC](https://forum.ansible.com/t/rollback-in-ansible/30324 "2019-05-14T09:54:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [May 14, 2019, 9:54am UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/1 "2019-05-14T09:54:20Z")

</div>

Hey all,

I want know when i play one task who failed if possible that ansible do rollback ?

Exemple :

- name: “create file”  
shell: touch test\_file.txt

When i play this task, she failed so i want one task or method for rollback please ?

I see in documentation officielle the module **aci\_config\_rollback** but i don’t konw how works this module…

[https://docs.ansible.com/ansible/latest/modules/aci\_config\_rollback\_module.html](https://docs.ansible.com/ansible/latest/modules/aci_config_rollback_module.html)

Can you help me ?

Thanks community ansible !! 🙂

Regards,

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [May 14, 2019, 10:19am UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/2 "2019-05-14T10:19:40Z")

</div>

> Hey all,
> 
> I want know when i play one task who failed if possible that ansible do rollback ?
> 
> Exemple :
> 
> - name: "create file"  
> shell: touch test\_file.txt
> 
> When i play this task, she failed so i want one task or method for rollback please ?

Hello Ryad,

what do you have in mind for the rollback for this task. Usually, if "touch" fails nothing changes on the target  
system.

> I see in documentation officielle the module \*aci\_config\_rollback\* but i don't konw how works this module...
> 
> [https://docs.ansible.com/ansible/latest/modules/aci\_config\_rollback\_module.html](https://docs.ansible.com/ansible/latest/modules/aci_config_rollback_module.html)

That looks like it applies for a very specific use case.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [May 14, 2019, 12:04pm UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/3 "2019-05-14T12:04:41Z")

</div>

Hey stefan,

Yes but if i want one procedure for install one application, exemple:

- block:

- name: task 1  
…  
…

- name: task 2  
…  
…

i want that if one task fails, I want him to go back on all the tasks that play it.

Do you understand what i say or no ?

Can you help me please 🙂

Regards

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [May 14, 2019, 12:29pm UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/4 "2019-05-14T12:29:12Z")

</div>

> Hey stefan,
> 
> Yes but if i want one procedure for install one application, exemple:
> 
> - block:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: task 1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;......  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.....
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- name: task 2  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;......  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;......
> 
> i want that if one task fails, I want him to go back on all the tasks that  
> play it.

You can write rollback tasks in a `rescue` section, followed by a fail task, but there is no automatic rollback functionality unless you write it yourself.

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [May 14, 2019, 12:36pm UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/5 "2019-05-14T12:36:51Z")

</div>

Hey,

Ok, thank you very much for your help !!

I will try rescue

Regards,

---

<div class="post-metadata">

**Author:** ![erichymowitz](https://avatars.discourse-cdn.com/v4/letter/e/9d8465/32.png) [@erichymowitz](https://forum.ansible.com/u/erichymowitz)\
**Post date:** [May 14, 2019, 4:01pm UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/6 "2019-05-14T16:01:00Z")

</div>

The problem you have is that ansible does not retain the old state of the machine when it makes changes. The fact that you executed the command “touch test\_file.txt” does not indicate whether test\_file.txt did or did not exist prior to running the command. So to “roll back”, do you erase the file? Change the date-stamp back to what it was?

Probably the closest thing you will find is a “block” with a “rescue” section attached, to specify what you want to happen in the event of an error.

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_blocks.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_blocks.html)

–EbH

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [May 14, 2019, 4:08pm UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/7 "2019-05-14T16:08:06Z")

</div>

Hey,

It is really very interesting this section rescue but if in my block I execute for example a script sql which does a lot of actions and that there is an error …

So what to put in the rescue section?

Thanks for your help ! 🙂

Regards,

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [May 14, 2019, 4:38pm UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/8 "2019-05-14T16:38:45Z")

</div>

> Hey,
> 
> It is really very interesting this section rescue but if in my block I  
> execute for example a script sql which does a lot of actions and that there  
> is an error ...

This is beyond the scope of ansible. You should have the rescue block do what is necessary to recover from your SQL script, or use something like a SQL transaction, but, again, it's beyond the scope of ansible.

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [May 15, 2019, 7:41am UTC](https://forum.ansible.com/t/rollback-in-ansible/30324/9 "2019-05-15T07:41:59Z")

</div>

Ok, i will play with rescue fonctionnality for do one rollback if there is one error in my block.

Thank you very much for your answer goy !! 😉

Regards,
