Rollback in Ansible ?

48 views
Skip to first unread message

Ryad karkar

unread,
May 14, 2019, 5:54:20 AM5/14/19
to Ansible Project
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...


Can you help me ?

Thanks community ansible !! :)

Regards,

Stefan Hornburg (Racke)

unread,
May 14, 2019, 6:20:04 AM5/14/19
to ansible...@googlegroups.com
On 5/14/19 11:54 AM, Ryad karkar wrote:
> 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

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

Regards
Racke

>
> Can you help me ?
>
> Thanks community ansible !! :)
>
> Regards,
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/5ef3adcb-671f-49d9-b4f7-db5afd6c835b%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/5ef3adcb-671f-49d9-b4f7-db5afd6c835b%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Ryad karkar

unread,
May 14, 2019, 8:04:42 AM5/14/19
to Ansible Project
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

Le mardi 14 mai 2019 12:20:04 UTC+2, Stefan Hornburg (Racke) a écrit :
On 5/14/19 11:54 AM, Ryad karkar wrote:
> 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

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

Regards
        Racke

>
> Can you help me ?
>
> Thanks community ansible !! :)
>
> Regards,
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to

James Cassell

unread,
May 14, 2019, 8:29:25 AM5/14/19
to Ansible List


On Tue, May 14, 2019, at 8:04 AM, Ryad karkar wrote:
> 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.
>

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

Ryad karkar

unread,
May 14, 2019, 8:36:51 AM5/14/19
to Ansible Project
Hey,

Ok, thank you very much for your help !!

I will try rescue

Regards,

Eric Hymowitz

unread,
May 14, 2019, 12:01:00 PM5/14/19
to Ansible Project
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.


--EbH

Ryad karkar

unread,
May 14, 2019, 12:08:07 PM5/14/19
to Ansible Project
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,

James Cassell

unread,
May 14, 2019, 12:38:57 PM5/14/19
to Ansible List


On Tue, May 14, 2019, at 12:08 PM, Ryad karkar wrote:
> 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

Ryad karkar

unread,
May 15, 2019, 3:41:59 AM5/15/19
to Ansible Project
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,
Reply all
Reply to author
Forward
0 new messages