restart networking: debian

797 views
Skip to first unread message

senorsmile

unread,
Oct 16, 2013, 11:58:18 AM10/16/13
to ansible...@googlegroups.com
I am trying to restart the networking on a debian box if the /etc/network/interfaces file is out of sync (i.e. first time setting up this server). 

I have tried 

  - name: restart networking
    service: name=networking state=restarted

But it just hangs.  

I have tried 

  - name: restart networking
    shell: shutdown now -r
    async: 120
    poll: 5


but the next task doesn't run because it errs out at:
    fatal: [192.168.11.123] => SSH encountered an unknown error during the connection. 


How do others restart networking?  

James Martin

unread,
Oct 16, 2013, 1:41:56 PM10/16/13
to ansible...@googlegroups.com
I can assure you that "shutdown now -r" is not how you restart networking.  That will restart you entire machine, which would lead to that fatal error message you're seeing.  As for the first method you mention that is hanging -- are you sure the settings you have assigned networking are valid?  Why are you restarting the network?

- James


--
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 ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

shaun

unread,
Oct 16, 2013, 1:47:16 PM10/16/13
to ansible...@googlegroups.com
why?  I am dealing with servers with several NIC's and dozens of virtual IP's

I realize restarting the client isn't the ideal solution, but tried it to see if it would work.  The interfaces file is fine, as all interfaces come up on reboot just fine.  


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/uAu8iYAN1Wg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

Matt Martz

unread,
Oct 16, 2013, 2:02:39 PM10/16/13
to ansible...@googlegroups.com
Debian networking is somewhat complicated.  The networking init script and networking upstart jobs don't do what most expect.  Those scripts and their underlying utilities only configure what they know about from the interfaces file.  If you remove something, or assign an IP to another interface, it won't deconfigure the previous configuration, it will only apply the newly provided configurations.

Example:
1. 10.10.10.10 on eth0
2. Edit /etc/network/interfaces and remove 10.10.10.10 from eth0 and assign to eth1
3. Restart networking

The result is that you now have 10.10.10.10 on eth0 and eth1, because they don't fully deconfigure the interface before applying the configuration of the interfaces file.

And it is not exactly straight forward to get it to completely deconfigure all interfaces and then reconfigure on start up.

I have a network init script for Debian/Ubuntu that mimics the functionality of the RHEL network init script at https://github.com/sivel/scripts/blob/master/ubuntu/network-compat.sh

Your other options are to use the `ip` command to do all of your work after modifying /etc/network/interfaces, but that could be complicated, without knowing exactly what changed in the interfaces file.

-- 
Matt Martz

Brian Coca

unread,
Oct 16, 2013, 2:10:17 PM10/16/13
to ansible...@googlegroups.com
ansible -s -K -m service -a "name=networking state=restarted" testmachines , works for me as long as the ip im using to access the box has not changed (wheezy and pangolin).

senorsmile

unread,
Oct 16, 2013, 4:11:27 PM10/16/13
to ansible...@googlegroups.com
That script looks great!  On Debian 7, the ifup (and ifdown and ifquery) commands don't have a -e option, so this errs out.  

senorsmile

unread,
Oct 16, 2013, 4:13:28 PM10/16/13
to ansible...@googlegroups.com
Strangely enough, this is basically what I tried before attempting to put it into my playbook.  I just tried again and waited about five minutes before determining that the interfaces were never going to come up.  From the machine, I can ifup eth0 (the control interface) and ansible continues along happily.  However, it doesn't seem to bring the interfaces back up directly from ansible.  

BTW, the client is running Debian 7.  

senorsmile

unread,
Oct 16, 2013, 4:15:38 PM10/16/13
to ansible...@googlegroups.com
I should mention that I have also tried simply: 

    shell: ifdown eth0; ifup eth0

to no avail.  Perhaps putting these commands into a shell script, copying the script to the client and then running it would do that trick? 

shaun

unread,
Oct 16, 2013, 4:28:45 PM10/16/13
to ansible...@googlegroups.com
Simple fix: 

### contents of etc.network.restartall ###
#!/bin/bash

ifdown -a
ifup -a
#################################

  - name: copy debian network restart script
    copy: src="etc.network.restartall" dest="/etc/network/restartall" owner=root group=root mode=0755

  - name: restart networking
    shell: /etc/network/restartall
    when: setupnetwork.changed


Works beautifully!

shaun

unread,
Oct 16, 2013, 4:29:54 PM10/16/13
to ansible...@googlegroups.com
I should add that the switch -a, only affects interfaces marked as auto in /etc/network/interfaces.  


Reply all
Reply to author
Forward
0 new messages