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.
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.
@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.
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)
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.