Asible: rebooting a network on Ubuntu

If you need to restart the network in the middle of the game on the Ubuntu server (12.04 in my case), you cannot use service :

 # service networking restart stop: Job failed while stopping start: Job is already running: networking 

It works on the command line, but with Ansible (1.8.4) it blocks you:

 command: ifdown eth0 && ifup eth0 

ifdown removes the interface, but ifup does not start

How to restart the interface?

+6
source share
2 answers

The solution is to run the command in a new shell:

 command: bash -c "ifdown eth0 && ifup eth0" 

You can also use a shell module:

 shell: "ifdown eth0 && ifup eth0" 
+7
source

I would recommend waiting 1 second between ifdown and ifup and doing ifup regardless of the exit code from ifdown. Also, you probably do not want to start the reset network every time you start this incomprehensible piece, so the when condition will prevent this:

 - name: Restart all network interfaces except loopback device shell: "ifdown --exclude=lo -a; sleep 1; ifup --exclude=lo -a" when: configure_lxc_bridge|changed 
+4
source

Source: https://habr.com/ru/post/982979/


All Articles