# push configuration and fallback if wrong

**URL:** <https://forum.ansible.com/t/push-configuration-and-fallback-if-wrong/14399>\
**Category:** Ansible Project\
**Created:** [January 22, 2014, 4:00pm UTC](https://forum.ansible.com/t/push-configuration-and-fallback-if-wrong/14399 "2014-01-22T16:00:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuele\_Giovanni\_Ton](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@Samuele\_Giovanni\_Ton](https://forum.ansible.com/u/Samuele_Giovanni_Ton)\
**Post date:** [January 22, 2014, 4:00pm UTC](https://forum.ansible.com/t/push-configuration-and-fallback-if-wrong/14399/1 "2014-01-22T16:00:01Z")

</div>

hello all,  
i started recently to look at ansible and, so far, it’s a great  
tool that amazes me and helps me in my work.

At the moment i’m puzzled with the following problem and i’m not  
sure if ansible is able to solve it and if so, what is the best practice to do that.

Suppose i have a service to update, let’s suppose for simplicity it’s  
apache and i just need to change some virtual hosts.

For sake of simplicity let’s say i’m using a directory conf.d so given **/etc/apache2/apache.conf**  
as the main config file, i put all my virtual hosts file inside a directory named  
**/etc/apache2/sites-enabled/** carefully putting one virtualhost per file.

In this way i can easily change VirtualHost configuration without modifying my main config  
and test config syntax by using command “ **apachectl configtest** ”; if that command goes OK  
i can safely restart apache otherwise i need to figure out what was wrong

This solve all those typo and syntax problem you may end up (e.g. adding a proxy pass directive  
without having mod\_proxy enabled and so on) while multitasking .

Now let’s suppose i have to do the same thing on 30 servers, i don’t want just to pull config files  
inside /etc/apache2/sites-enabled/ , do apachectl configtest and if it fail print a warning and  
revert back to old config for all hosts and warn me; if the command succedes then restart apache.

Does ansible support such a complex task? if so, what is the best practice to do that?  
so far i could only thing of something like “one master, many slaves” in which there’s a  
master apache to pull all my config to all the other slaves but i fail to see how to revert back  
to old config in case of failure.

The other solution would be based on git/svn where last config resides: every apache “pulls” config  
from that git and in case of fails revert to the previous but even this one doesn’t seems to be a viable  
one.

Am i on the right track, or i’m simply using ansible for something it wasn’t build for ?

Many Thanks

Samuele

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 22, 2014, 4:16pm UTC](https://forum.ansible.com/t/push-configuration-and-fallback-if-wrong/14399/2 "2014-01-22T16:16:24Z")

</div>

copy and template have validate=“” for this, check docs for an example with sudoers file.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [January 22, 2014, 4:19pm UTC](https://forum.ansible.com/t/push-configuration-and-fallback-if-wrong/14399/3 "2014-01-22T16:19:20Z")

</div>

sorry, that will do it for 1 host, not all. but if you capture the errors you can set tasks to revert it all.

ignore\_errors: yes  
register: results

revert  
when:results|failed
