On 31.05.16 12:57 Jahedh Mahmud wrote:

> I'm new to Ansible and have been researching a way to stop a task from 
> making a change if any of the tasks in the playbook fail.

Add a when-conditional to the second task, so that it only runs if the
first one went fine.

> Is there a way to do this? my playbook has three tasks, if the install 
> Django fails i don't want the first two to commit. But they are reported as 
> 'changed' once the playbook finishes.

You can only skip later tasks, if one task fails. Also, tasks are done
one after the other, so there is no easy way (at least I know none) to
only run if all tasks would succeed.


> tasks:
> 
>      - name: update
> 
>        command: apt-get update

I would rather use the apt module here.
https://docs.ansible.com/apt_module.html

>      - name: install pip
> 
>        apt: pkg=python-pip

Same here.
> 
>  
> 
>     - name: install django
> 
>        command: pip install django

You could run this task with a conditional, so it is executed only, if
the first two tasks went without errors.

If these are your three tasks, what reasons do you have for the first
two not to commit, if the third fails? Updating the system and
installing pip do not seem to be causing any pain.

Johannes


-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/574D9B2D.4050308%40ojkastl.de.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to