# Actions before installing a new file

**URL:** <https://forum.ansible.com/t/actions-before-installing-a-new-file/13722>\
**Category:** Ansible Project\
**Created:** [October 19, 2013, 9:05am UTC](https://forum.ansible.com/t/actions-before-installing-a-new-file/13722 "2013-10-19T09:05:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://forum.ansible.com/u/Brian_Candler)\
**Post date:** [October 19, 2013, 9:05am UTC](https://forum.ansible.com/t/actions-before-installing-a-new-file/13722/1 "2013-10-19T09:05:05Z")

</div>

I am looking for suggestions for the cleanest way to implement the following.

- Have a template for /etc/network/interfaces

- If it is different to the current version, then:

- before the new version is installed, run “service networking stop”

- install the new version

- run “service networking start”

I am considering installing /etc/network/interfaces.ansible, and then having a handler something like

shell: if [! cmp /etc/network/interfaces /etc/network/interfaces.ansible]; then service networking stop; cp /etc/networking/interfaces.ansible /etc/networking/interfaces; service networking start; fi

Is there a better way?

Thanks,

Brian.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 20, 2013, 1:25am UTC](https://forum.ansible.com/t/actions-before-installing-a-new-file/13722/2 "2013-10-20T01:25:06Z")

</div>

I’m not sure you would want to disable networking in the middle of an Ansible run, also it is fine to replace a networking config file and then restart the service.

What you could do is just template the file and then have a handler be used to restart it on change, but just for that interface.

---

<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:** [October 20, 2013, 12:41pm UTC](https://forum.ansible.com/t/actions-before-installing-a-new-file/13722/3 "2013-10-20T12:41:27Z")

</div>

@micheal, if there are virtual interface changes, restarting with new config might leave the system in a bad state (won’t down interfaces you removed). I suppose this is why he wants to stop with old file and start with new.

@brian, I see no ‘better’ way of doing this as most ansible actions would need the networking which you just stopped.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 20, 2013, 1:41pm UTC](https://forum.ansible.com/t/actions-before-installing-a-new-file/13722/4 "2013-10-20T13:41:45Z")

</div>

You won’t be able to stop/start as you won’t be able to talk after you have stopped.

You can of course use the ‘script’ module to push something do all three (stop, cp, start)

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://forum.ansible.com/u/Brian_Candler)\
**Post date:** [October 20, 2013, 5:07pm UTC](https://forum.ansible.com/t/actions-before-installing-a-new-file/13722/5 "2013-10-20T17:07:10Z")

</div>

> I’m not sure you would want to disable networking in the middle of an Ansible run, also it is fine to replace a networking config file and then restart the service.

Unfortunately that doesn’t work with Debian/Ubuntu systems. ‘stop’ or ‘restart’ only downs the things which are currently listed in /etc/network/interfaces.

> What you could do is just template the file and then have a handler be used to restart it on change, but just for that interface.

This is something a bit more general: it’s reconfiguring the server’s interfaces (as a VM platform). It will be adding new bridges and interfaces, and may be removing old bridges and interfaces.

It’s running with ansible\_connection=local so I’m not too worried about downing the interfaces briefly.

But thanks, it looks like a script which does stop/cp/start is what’s needed.

Regards,

Brian.
